John Dagpin
John Dagpin

Reputation: 33

why is my delete button return a error 404

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');

this is my data this happen when i click the delete button

Upvotes: 0

Views: 173

Answers (2)

Mayur Sojitra
Mayur Sojitra

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

Shahrukh
Shahrukh

Reputation: 478

Change your route method from POST to DELETE. Like this

Route::delete('/index/{id}', 'StudentController@destroy');

Upvotes: 2

Related Questions