Hello i'm still new to laravel and I've searching the web for almost 3 hours about this issue I have I tried many things but it didn't work.
So basicly I have a page with a button , when I click that button "Approve" I want to update the value from 0 to 1 (the column is of type boolean). This is my controller :
public function approve($id){
$training = Training::find($id);
$training->update(['Approved' =>'1']);
// $training->Approved = 1;
// $training->save();
return redirect('/trainings')->with('success', 'Training Approved');
}
This is page section with the button it's in the folder trainings and has the name " 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()!!}
and the routes (I guess this is the part I'm doing wrong):
Route::post('/trainings',['as' =>'trainings.show', 'uses' => 'TrainingsController@approve']);
The error I get when clicking the button is this :
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
Thank you for your Help
Since the route is post, you should change form method to post too:
{{ Form::hidden('_method','POST') }}
Or:
{!! Form::open(['method' => 'post', 'action' => ....
You also need to add id to the route definition:
Route::post('trainings/{id}', ['as' => 'trainings.show', 'uses' => 'TrainingsController@approve']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With