如何解决laravel中删除时出现409页未找到错误?

时间:2020-05-25 10:12:24

标签: php laravel

enter image description here

    <form method="POST" action="/posts/{{$post->id}}">
        <input type="hidden" name="_method" value="DELETE">
        <input type="submit" value="DELETE">
    </form>

我有这个方法,应该在“ PostsController”中调用“ destroy”方法。但是,当我点击删除按钮时,出现“ 409页面已过期”错误。

enter image description here

我该如何解决?

2 个答案:

答案 0 :(得分:1)

在您的表单内,添加一个csrf字段。您可以这样做:

<form method="POST" action="/posts/{{$post->id}}">
        @csrf
        <input type="hidden" name="_method" value="DELETE">
        <input type="submit" value="DELETE">
    </form>

在此处详细了解:https://laravel.com/docs/7.x/csrf

答案 1 :(得分:1)

csrf丢失。

您必须在表单内添加csrf

<input type="hidden" name="_token" value="{{ csrf_token() }}">