部署后,当我尝试使用delete route
时,会抛出以下错误:
419 | PAGE EXPIRED
Failed to load resource: the server responded with a status of 419 ()
触发路由的vue组件内的函数:
const destroyEvent = (record) => {
if (confirm('Delete event?')) {
Inertia.delete(route('admin.event.destroy', {
id: record.id,
title: record.title,
image_path: record.image_path,
}), { preserveScroll: true })
}
}
Web路由:
Route::delete('/admin/event/destroy', [EventsController::class, 'destroyEvent'])->name('admin.event.destroy');
请求似乎没有到达EventsController
,我已经用dd()
测试过了。
根据this stack question,这可能是一个CSRF
令牌问题。我已经尝试了所有建议,但它没有帮助。虽然注解:
\App\Http\Middleware\VerifyCsrfToken::class
从app\Kernel.php
移除419 | PAGE EXPIRED
屏幕,而显示空白页面。这是否表示CSRF
有问题?
从这个laracasts question,我还尝试添加:
public function boot()
{
if($this->app->environment('production') || $this->app->environment('staging'))
{
\URL::forceScheme('https');
}
}
到AppServiceProvider.php
,而问题没有改善。
有办法解决吗?
1条答案
按热度按时间1yjd4xko1#
我找到了一个变通办法,即使用
form.delete
而不是Inertia.delete
:了解
form
帮助器处理CSRF
与处理Inertia
的不同之处将是非常有用的。