删除操作在laravel中不起作用?

时间:2017-03-30 03:36:28

标签: php forms laravel-5 delete-row

我有一个包含删除按钮的表单。

 <form method="post" id="delform" action="{{ url('/templates/delete',[$template->template_id]) }}">
    {{ method_field('DELETE') }}
  {{ csrf_field() }}

 <input type="submit" class="btn btn-danger" id="del" value="delete>

  </form>

然后在我的路线web.php:

Route::delete('/templates/delete/{id}','TemplateController@delete');

当我点击删除时,我收到此错误:

enter image description here

我正在做什么,请帮忙吗?提前谢谢

我在这里添加了我的composer.json:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.6.4",
    "laravel/framework": "5.4.*",
    "laravel/tinker": "~1.0",
    "maatwebsite/excel": "~2.1.0"        "rmccue/requests": ">=1.0"    },
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~5.7"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
},
"scripts": {
    "post-root-package-install": [
        "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postInstall",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan optimize"
    ]
},
"config": {
    "preferred-install": "dist",
    "sort-packages": true
}
}

这是控制台日志:

enter image description here

1 个答案:

答案 0 :(得分:1)

您忘记使用双引号来关闭输入提交的值

<input type="submit" ... value="delete">

包装后的作曲家json中的逗号:

"maatwebsite/excel": "~2.1.0",

最后,HTML表单不支持PUT,PATCH或DELETE操作。因此,在定义从HTML表单调用的PUT,PATCH或DELETE路由时,您需要向表单添加隐藏的_method字段。使用_method字段发送的值将用作HTTP请求方法。

<input type="hidden" name="_method" value="DELETE">

您可以使用method_field助手生成_method输入:

{{ method_field('DELETE') }}

Laravel routes documentation

查看rest conventions