In a Laravel 5.5 project, I have a student controller with destory
method.
public function destroy(Student $student)
{
//destroy $student and redirect
}
I have the route for the controller as follows
Route::delete('/student/{id}', 'StudentController@destroy');
Now let's get to the question.
I have a page to manage students and it has a delete button.
<a class="btn btn-danger"
href="{{ action('StudentController@destroy', ['id' => $student->id]) }}" >
Delete
</a>
when i click the delete button it throws method not allowed exception
since the request is not a delete request. Is there any way/workaround to specify/spoof the request method through action()/route()
helper functions?
Normally I would have created a form with a hidden _method="delete"
input and post the form. but if I am adding an update button, then I would have to create another form with a hidden _method="patch"
in it and I don't think this is a good practice.
please give some ideas to go forward.