vendredi 11 novembre 2016

Laravel5 link_to_action doesn't work when trying to delete an article

I've created a basic blog with Laravel, then when I tried to add the delete method to the 'show' view, but after I confirm the deletion, nothing happens further.

The route looks like:

DELETE | articles/{articles} | articles.destroy | App\Http\Controllers\ArticlesController@destroy

My code looks the following:

In the view called 'show', where the selected article is displayed, below I wanted to add the link like:

{!! link_to_action('ArticlesController@destroy', 'Delete Article', $article->id, ['method'=>'DELETE', 'class'=>'btn btn-danger', 'onClick'=>'return confirm("Are you sure you want to delete this item?")']); !!}

In the ArticlesController, I've written the 'destroy' function just like:

    public function destroy(Article $article) {

        $article->delete();

        return redirect('articles')->with([
            'flash_message' => 'Article successfully deleted.',
            'flash_message_important' => 'true',
        ]);
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire