- Create a route
Route::delete('articles/{id}', [
'as' => 'delete_article_path',
'uses' => 'ArticlesController@destroy'
]);
- Hit the route
<a href="{!! route('delete_article_path') !!}"> Delete Article </a>
- implement the destroy() method in the ArticlesController
public function destroy($id)
{
// find the article you want to delete by ID
$article = Article::find($id);
$articleStatus = $article->delete();
// if delete failed
if (!$articleStatus)
{
return view('articles'); // return a view with a failed flash message
}
// if the article was deleted successfully
return view('articles'); // return a view with a success flash message
}
There was a video where Jeffrey said that it's better to do delete requests through a form instead of a link (I think it has something to do with CSRF)