我已经安装了CORS软件包,并且似乎正在运行(无控制台错误),但是我现在遇到500错误Class throttle does not exist
。我无法理解。我相信这可能与我的Kernel.php文件有关?
Laravel Framework 5.8.5
Cors库https://packagist.org/packages/barryvdh/laravel-cors。
我尝试过composer update
和composer dump-autoload
Kernel.php
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
\Barryvdh\Cors\HandleCors::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
];
/**
* The priority-sorted list of middleware.
*
* This forces non-global middleware to always be in the given order.
*
* @var array
*/
protected $middlewarePriority = [
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\Authenticate::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authorize::class,
];
}
ApiController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\User;
use Illuminate\Support\Facades\Hash;
class ApiController extends Controller
{
public function generateAccessToken(Request $request)
{
$http = new \GuzzleHttp\Client;
$response = $http->post('http://social.kindle/oauth/token', [
'form_params' => [
'grant_type' => 'password',
'client_id' => '1',
'client_secret' => 'yilrEuaPympsmS4ThXx81dvnzAxwY7nQYBpbnLtr',
'username' => $request->email,
'password' => $request->password,
'scope' => '',
],
]);
return json_decode((string) $response->getBody(), true);
}
public function post() {
//header('Access-Control-Allow-Origin: *');
dd('test');
}
}
api.php
<?php
Route::get('/access-token','ApiController@generateAccessToken');
Route::post('/customer-dash/post', function (Request $request) {
dd('test');
//return Auth::user();
});
Route::middleware('auth:api')->get('/user', function (Request $request) {
return Auth::user();
});
错误堆栈
{
"message": "Class throttle does not exist",
"exception": "ReflectionException",
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php",
"line": 794,
"trace": [
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php",
"line": 794,
"function": "__construct",
"class": "ReflectionClass",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php",
"line": 671,
"function": "build",
"class": "Illuminate\\Container\\Container",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php",
"line": 619,
"function": "resolve",
"class": "Illuminate\\Container\\Container",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Application.php",
"line": 757,
"function": "make",
"class": "Illuminate\\Container\\Container",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 152,
"function": "make",
"class": "Illuminate\\Foundation\\Application",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 104,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 682,
"function": "then",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 657,
"function": "runRouteWithinStack",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 623,
"function": "runRoute",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 612,
"function": "dispatchToRoute",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 176,
"function": "dispatch",
"class": "Illuminate\\Routing\\Router",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 30,
"function": "Illuminate\\Foundation\\Http\\{closure}",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/barryvdh/laravel-cors/src/HandleCors.php",
"line": 59,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Barryvdh\\Cors\\HandleCors",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/fideloper/proxy/src/TrustProxies.php",
"line": 57,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Fideloper\\Proxy\\TrustProxies",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 21,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 21,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
"line": 27,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
"line": 62,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 163,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line": 53,
"function": "Illuminate\\Pipeline\\{closure}",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 104,
"function": "Illuminate\\Routing\\{closure}",
"class": "Illuminate\\Routing\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 151,
"function": "then",
"class": "Illuminate\\Pipeline\\Pipeline",
"type": "->"
},
{
"file": "/home/vagrant/code/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 116,
"function": "sendRequestThroughRouter",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
},
{
"file": "/home/vagrant/code/public/index.php",
"line": 55,
"function": "handle",
"class": "Illuminate\\Foundation\\Http\\Kernel",
"type": "->"
}
]
}
我正在尝试从前端Angular代码库中访问“ / customer-dash / post” URL,但这就是当我收到500错误时的提示。谁能帮助解决500错误?
谢谢
答案 0 :(得分:0)
好像您已经从$routeMiddleware
数组中删除了一些中间件定义。
如果将以下内容添加到`Http / Kernel.php文件中,该错误应会消失!
protected $routeMiddleware = [
// ...
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];