表单添加验证后 网页显示 您访问的网页出错了! 网络连接异常、网站服务器失去响应
public function index(Request $request) {
$this->validate($request, ['title' => 'required|unique|max:255',
'category'=>'required',
'price'=>'required|min:0',
'discount'=>'required|min:0',
'intro'=>'required']);
if($input=Input::all()){
$good=new Good();
$good->create($input);
return redirect('/');
}
else {
return view('addGood');
}
}
方法里面一写$this->validate这个网页就打不开
$this->validate($request, ['title' => 'required|unique|max:255',
'category'=>'required',
'price'=>'required|min:0',
'discount'=>'required|min:0',
'intro'=>'required']);
if($input=Input::all()){
$good=new Good();
$good->create($input);
return redirect('/');
}
else {
return view('addGood');
}
}
方法里面一写$this->validate这个网页就打不开
1 个回复
iwen
赞同来自:
自定义规则:
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
if ($validator->fails()) {
return redirect('post/create')
->withErrors($validator)
->withInput();
}
可以试下以上格式