OunknownO OunknownO - 28 days ago 9
PHP Question

Laravel delete button throwing out error "page couldn't be found

this is my code

view

<form action="/categories/ {{ $category->id }}" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}

<button>Delete Task</button>
</form>


controller method

public function destroyCategory($id)
{

Categories::findOrFail($id)->delete();

return redirect('/categories');
}


route

Route::post('categories','FilesController@destroyCategory');


Form is in partial view, can that be a problem

Answer

You send DELETE method from your form but you catch it as a post instead of delete inside your route file & also you not assign URL parameter in your route file.

<form action="/categories/{{ $category->id }}" method="POST">
    {{ csrf_field() }}
    {{ method_field('DELETE') }}

    <button type="submit">Delete Task</button>
</form>

route.php

Route::delete('categories/{id}','FilesController@destroyCategory');
Comments