后会无期28
2017-01-24 18:00
//修改学生
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);
}
解决了吗?同求啊。。到底是差什么哦
validate要申明的吧
轻松学会Laravel-表单篇
32662 学习 · 255 问题
相似问题