我正在尝试添加一个表单按钮以删除记录,但是由于某些原因,csrf令牌未插入该记录。我已经尝试了很多方法,但是无法正常工作。有什么建议吗?
<div class="row">
<a href="{{ route('publicaciones.show', $id)}}" class="btn btn-success btn-sm h-25 d-inline-block mr-3">Ver</a>
<a href="{{ route('publicaciones.show', $id)}}" class="btn btn-primary btn-sm h-25 d-inline-block">Editar</a>
<form method="POST" action="{{ url("publicaciones/{$id}") }}" class="col">
@csrf
@method('DELETE')
<button class="btn btn-danger btn-sm" type="submit" id="eliminar">Eliminar</button>
</form>
</div>
附加图片:
答案 0 :(得分:0)
通常,您的路线不使用Web中间件。确保将https://www.googleapis.com/auth/cloud-platform
用于该路由,并确保routes/web.php
具有RouteServiceProvider
示例:
Route::middleware('web')
或者您可以手动将以下路线添加到每条路线中:
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')->namespace($this->namespace)->group(base_path('routes/web.php'));
}
根据Route::group(['middleware' => ['web']], function () {
// your routes here
});
网络中间件的评论,您的路由将获得会话状态,CSRF保护等。