Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel/PHP:cors类不存在_Php_Laravel_Cors - Fatal编程技术网

Laravel/PHP:cors类不存在

Laravel/PHP:cors类不存在,php,laravel,cors,Php,Laravel,Cors,我的一些api调用有问题。通过使用- 对飞行前请求的响应未通过访问控制检查 但是问题并不止于此,一些api调用抛出了这个错误 “错误”:“类cors不存在”,“调试”:{“代码”:-1,“行”:767,“跟踪”:[{“文件”:“/home/xxxxxx/Workspace/xxxxxx/vendor/laravel/framework/src/light/Container/Container.php”,“行”:767…]} 我能够按照中的说明进行操作,包括将其添加到kernel.php,创建c

我的一些api调用有问题。通过使用-

对飞行前请求的响应未通过访问控制检查

但是问题并不止于此,一些api调用抛出了这个错误

“错误”:“类cors不存在”,“调试”:{“代码”:-1,“行”:767,“跟踪”:[{“文件”:“/home/xxxxxx/Workspace/xxxxxx/vendor/laravel/framework/src/light/Container/Container.php”,“行”:767…]}

我能够按照中的说明进行操作,包括将其添加到kernel.php,创建config/cors.php,路径设置为
'paths'=>['api/*]],
,最后将其添加到我的路由中:

Route::group(['middleware' => 'cors'], function() {
    Route::middleware('auth:api')->namespace('Api')->group(function () {

     
        Route::middleware('admin')->prefix('admin')->namespace('Admin')->group(function() {
            Route::get('dashboard/statistics', 'DashboardController@index');

...
我使用的是较旧版本的Laravel(5.6)和PHP7.4。非常感谢您的帮助

在新选项卡上打开端点时,出现错误:


Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException No message

HandleCors
类添加到
config/app.php
别名部分,如下所示

'cors' => \Fruitcake\Cors\HandleCors::class,

在将
HandleCors
添加到
config/app.php
之后,是否运行了
composer dump autoload
命令?

我删除了路由器上的中间件

Route::group(['middleware' => 'cors'], function() {
    Route::middleware('auth:api')->namespace('Api')->group(function () {

 
        Route::middleware('admin')->prefix('admin')->namespace('Admin')->group(function() {
            Route::get('dashboard/statistics', 'DashboardController@index');

...
公正

Route::middleware('admin')->prefix('admin')->namespace('Admin')->group(function() {
    Route::get('dashboard/statistics', 'DashboardController@index');

感谢您的回复,但不幸的是,问题没有得到解决。我还运行了
php artisan缓存:clear
php artisan配置:clear
,但这并没有解决我的问题。我还在尝试清除缓存-
php artisan缓存:clear
和配置
php artisan配置:clear