我希望表格中的某些值可编辑,因此我创建了这个简单的自定义表单。但这会抛出方法错误,不允许http异常。有什么帮助吗?
<form action="{{ url('/idx-test/update-this-student/'. $student->id)}}" class="" method="POST">//changing this to put, patch does not solve the error
路线
Route::post('/idx-test/update-this-student/{id}', 'StudentController@updateThisStudent'); //again changing this to patch,or put does not help
控制器
public function updateThisStudent(StudentRequest $request, $id)
{
$student = Student::findOrFail($id);
$student->update($request->all());
// return redirect('city');
echo "updated";
}
StudentRequest
public function rules()
{
return [
'firstname' => 'required|alpha|min:2|max:10',
'lastname' => 'required|alpha|min:2|max:10',
'bday' => 'required|date',
'address' => 'required|min:10',
'zip' => 'required|min:4|max:10',
'phone' => 'required|digits:7',
'mobile' => 'required|digits:11',
'email' => 'required|email',
'city_id' => 'required',
'yearlevel_id' => 'required',
'section_id' => 'required',
];
}
答案 0 :(得分:0)
添加这一小段代码
<input type="hidden" name="_method" value="PATCH">
我的问题解决了