我目前注入我的口才模型在我的控制器是这样的:访问依赖注入的类变量
class ComputerController extends BaseController {
public function __construct(User $user, Machine $machine, MachineType $machineType){
$this->user = $user;
$this->machine = $machine;
$this->machineType = $machineType;
}
这样我就可以迅速访问模式:
$this->machine->get();
但如何我访问属性,如存储在类中的验证规则?
我用
Machine::$rules;
但使用这种方法
$this->machine->$rules
不工作。有没有办法检索存储在雄辩模型中的规则数组?
这是我的类为例:
class Machine extends Eloquent {
protected $table = 'machines';
public $timestamps = true;
protected $softDelete = true;
public static $rules = array(
'computer_name' => 'required|min:2',
'computer_user' => 'required',
'computer_ip' => 'ip'
);
非常感谢!
编辑::试图根据安东尼奥只是为了测试,仍然无济于事,带来了一个错误,当我运行它。
错误:
出现什么错误?你试过了,$ this-> machine-> rules? – gonzalon
我对口才并不熟悉,但如果您确实需要绕过api,则可以尝试使用php的ReflectionClass和ReflectionProperty类: http://www.php.net/manual/en/reflectionclass.getproperties.php http://www.php.net/manual/en/class.reflectionproperty.php – jstaab
@gonzalon我得到这个错误与您的建议:参数2传递给Illuminate \ Validation \ Factory :: make()必须是类型在第211行中定义的C:\ Program Files(x86)\ Ampps \ www \ www.helpdesk.dev \ vendor \ laravel \ framework \ src \ Illuminate \ Support \ Facades \ Facade.php文件中调用null,并定义为 –