我用 Laravel 创建了一个基本博客,然后当我尝试将删除方法添加到“显示” View 时,但在确认删除后,没有任何反应。
路线如下:
DELETE | articles/{articles} | articles.destroy | App\Http\Controllers\ArticlesController@destroy
我的代码如下所示:
在显示所选文章的“显示” View 中,我想在下面添加如下链接:
{!! 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?")']); !!}
在 ArticlesController 中,我编写了“destroy”函数,如下所示:
public function destroy(Article $article) {
$article->delete();
return redirect('articles')->with([
'flash_message' => 'Article successfully deleted.',
'flash_message_important' => 'true',
]);
}
最佳答案
问题出在 link_to_action
上,它不包含在 Laravel 5 中。请参阅 this post .
要使用 link_to_route 帮助程序,您需要提取 "laravelcollective/html": "~5.0"
包。
关于javascript - Laravel5 link_to_action 在尝试删除文章时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40550317/