【发布时间】:2018-06-04 13:47:15
【问题描述】:
您好,我还是 laravel 的新手,我已经在网上搜索了将近 3 个小时关于这个问题我尝试了很多东西,但没有成功。
所以基本上我有一个带有按钮的页面,当我单击该按钮“批准”时,我想将值从 0 更新为 1(该列是布尔类型)。 这是我的控制器:
public function approve($id){
$training = Training::find($id);
$training->update(['Approved' =>'1']);
// $training->Approved = 1;
// $training->save();
return redirect('/trainings')->with('success', 'Training Approved');
}
这是页面部分,其按钮位于培训文件夹中,名称为“show.blade.php”:
{!!Form::open(['action' => ['TrainingsController@approve',$training->TrainingsID], 'method' => 'POST','class' => 'pull-left'])!!}
{{Form::hidden('_method','PUT')}}
{{Form::submit('Approve',['class' => 'btn btn-success'])}}
{!!Form::close()!!}
还有路线(我想这是我做错的部分):
Route::post('/trainings',['as' =>'trainings.show', 'uses' => 'TrainingsController@approve']);
单击按钮时出现的错误是:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
感谢您的帮助
【问题讨论】:
标签: php jquery mysql laravel eloquent