BadMethodCallException in Controller.php line 105: Method [validate] does not exist.
//修改学生
public function updates(Request $request,$id)
{
$student = Student::find($id);
if($request->isMethod('POST')){
//1:控制器验证
$this->validate($request, [
'Student.name' => 'required|min:2|max:20',
'Student.age' => 'required|integer',
'Student.sex' => 'required|integer',
], [
'required' => ':attribute 为必填项',
'min' => ':attribute 长度不符合要求',
'integer' => ':attribute 必须为整数',
], [
'Student.name' => '姓名',
'Student.age' => '年龄',
'Student.sex' => '性别',
]);
$date = $request->input('Student');
$student->name =$date['name'];
$student->age =$date['age'];
$student->sex =$date['sex'];
if($student->save()){
return redirect('student/index')->with('success','修改成功-'.$id);
}
}
return view('student/updates',[
'student'=>$student
]);
// var_dump($student);
}