【发布时间】:2015-12-09 08:03:04
【问题描述】:
美好的一天,
我正在尝试将变量发送到模型以在所有函数中使用,而不将其作为参数传递给所有函数, 这是我所做的,但它不起作用,任何人都可以找出问题所在?
SomethingController.php
public function store(){
$user_value = \Request::input('value'); // get value from user
$somethingObj = new \App\Something(['user_value' => $user_value ]);
$somethingObj->doSomething();
}
Something.php
public $value;
public function __constructor($attributes){
$this->value = $attributes['user_value'];
}
public function doSomething(){
if($this->value){
// this is not working , $value not working also $this->$value didn't work too
doSomething();
}else{
doOtherThing();
}
}
【问题讨论】:
-
Something是否扩展Eloquent?
标签: php oop laravel model structure