Reputation: 33
This is the html code:
<form name="student" action='{{action('StudentController@destroy',$data->id)}}' method="POST">
@method('DELETE')
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<button class="btn btn-outline-danger" type="submit" value="submit">Delete</button>
</form>
this is the controller:
public function destroy($id)
{
$data = students::find($id);
$data->delete();
return redirect('/index')->with('failed','Acc Deleted');
}
This is the route:
Route::post('/index/{$id}', 'StudentController@destroy');
Upvotes: 0
Views: 173
Reputation: 712
There are two way to fix this
@method('DELETE') //Remove this from you form element
or
Route::delete('/index/{id}', 'StudentController@destroy');
//replace post method with delete
Upvotes: 0
Reputation: 478
Change your route method from POST
to DELETE
. Like this
Route::delete('/index/{id}', 'StudentController@destroy');
Upvotes: 2