【发布时间】:2016-03-02 11:54:35
【问题描述】:
我正在学习 Laravel 5.2。我正在尝试做一个表单验证示例。已阅读文档进行验证,并且我的代码使用创建和存储方法使用验证请求类正在工作。现在我正在尝试以相同的方法同时执行POST 和GET。我已经创建了我的request 类,我的规则方法被定义为这样
public function rules()
{
if($this->method() == 'POST'){
return [
'first_name' => 'required'
];
}else{
return [];
}
}
我的控制器方法被声明为
public function create(myRequest $request){
//save and display the data
}
但是当我加载我的方法时,我得到一个空白页,上面写着forbidden。我尝试为 GET 返回 null 值,但它不起作用。
Argument 2 passed to Illuminate\Validation\Factory::make()
must be of the type array, null given
不能做这样的事情吗?
【问题讨论】: