首页 > 解决方案 > Laravel 发布 - 419 未知状态

问题描述

我正在尝试使用这个包,它可以满足我的一切需求。因此,除了我上传图片时,一切似乎都正常。它根本不会用到 UtilsController@uploadfile 函数。

Route::post('/uploadfile', 'UtilsController@uploadfile');



public function uploadfile(Request $request){
        $img = $request->img;
        $newlocation = $request->newlocation;
        $filename = $request->filename;

        return file_put_contents ($newlocation . "/" . $filename , $img );
    }

但是当我检查网络时,一切似乎都很好......

在此处输入图像描述

在此处输入图像描述

我收到此错误:419 未知状态

任何想法?

标签: ajaxlaravel

解决方案


有时可能存在我们可能希望在不需要 CSRF_TOKEN 的情况下存在路由的情况。我们可以简单地在 VerifyCsrfToken 中间件的 except 数组中添加这些 URI 或路由,如下所示

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
 /**
  * The URIs that should be excluded from CSRF verification.
  *
  * @var array
  */
 protected $except = [
  'stripe/*',
  'http://example.com/foo/bar',
  'http://example.com/foo/*',
 ];
}

推荐阅读