Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

El_Matella's avatar

Calling a DELETE request on a link?

Hi everyone!

Today I am trying to implement a simple user interface for my users to allow them to delete an article. What is the best way to do it? I always done that in my previous projects using a $_GET['delete'] variable. But now I would like to use the REST structure, so I should use DELETE requests. How should I do that, is it doable only in Ajax? I really don't know how to begin with that.

Thank you very much for your help!

0 likes
2 replies
davorminchorov's avatar
Level 53
  • 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)

1 like
El_Matella's avatar

Thank you very much for your response, this will help me a lot now and in the future!

Please or to participate in this conversation.