【发布时间】:2018-12-26 11:42:28
【问题描述】:
我在 laravel 中测试护照时遇到问题,当 postman 中的 testo 给我一个错误时。
"message": "",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"file": "/data/www/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
"line": 179,
路由/api.php
Route::group([
'prefix' => 'api',
'middleware' => ['auth.api']
], function () {
Route::post('details', 'API\UserController@details');
});
用户控制器.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,
]
],
];
验证CRFSToken.php
protected $except = [
//'authenticate'
'/api/*'
];
我哪里错了?路线在 route: list 中列出
【问题讨论】:
-
你的邮递员发送到什么路线?
-
你已经放置了一个中间件
'middleware' => ['auth.api'],它有什么作用?您是否随请求一起发送任何 API 密钥(例如)? -
您不应该真正将 dd 命令与邮递员一起使用,它是专为浏览器设计的。只需返回一个 json 或字符串。在已经设置好的 api.php 上编写路由时不需要 Api 前缀。这可能是你的问题。