javascript - Laravel5 link_to_action 在尝试删除文章时不起作用

标签 javascript php laravel laravel-5

我用 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/

相关文章:

php - ubuntu 16.04 中 laravel 安装错误

javascript - 正则表达式以像素为单位转换所有 rem-calc

php - 在 Laravel 5 中将数据保存到数据库中

javascript - 悬停时用淡入淡出交换图像

php - MySQL 语法错误——我哪里出错了?

javascript - 如何在 php 代码中使用 jQuery 变量?

php - 如何在 Laravel 5 中对合并的集合进行分页?

php - Laravel 查询两个日期列数据库中的两个日期

javascript - 下划线函数有什么用?

javascript - Angular Js : onchange in directive at class attribute is not working