我在laravel中测试passport时遇到问题,testo在postman中显示错误。
"message": "",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"file": "/data/www/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"line": 179,
字符串
routes/api.php
Route::group([
'prefix' => 'api',
'middleware' => ['auth.api']
], function () {
Route::post('details', 'API\UserController@details');
});
型
UserController.php
public function details()
{
dd("Ijdsijds");
$user = Auth::user();
return response()->json(['success' => $user], $this->successStatus);
}
型
kernel.php
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',
'cors' => [
\Barryvdh\Cors\HandleCors::class,
]
],
];
型
VerifyCRFSToken.php
protected $except = [
//'authenticate'
'/api/*'
];
型
我在哪里出错了?路线在route:list中列出
2条答案
按热度按时间9njqaruj1#
删除
'prefix' => 'api'
。因为“/API”默认添加在url中,如果你不想在url中添加“/API”,请从RouteServiceProvider
中删除'prefix' => 'api'
这里RouteServiceProvider文件代码:字符串
jv2fixgn2#
因为你使用的是无状态的
routes/api.php
,所以你不会得到任何会话值(这里是Auth
)。要获取值,请使用
Passport
Helpful link或使用JWT