php Laravel 5.6中的API路由与Postman不工作

vjrehmav  于 5个月前  发布在  PHP
关注(0)|答案(2)|浏览(53)

我在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中列出

9njqaruj

9njqaruj1#

删除'prefix' => 'api'。因为“/API”默认添加在url中,如果你不想在url中添加“/API”,请从RouteServiceProvider中删除'prefix' => 'api'这里RouteServiceProvider文件代码:

$this->routes(function () {
        Route::middleware('api')
            ->prefix('api')
            ->group(base_path('routes/api.php'));

        Route::middleware('web')
            ->group(base_path('routes/web.php'));
    });

字符串

jv2fixgn

jv2fixgn2#

因为你使用的是无状态的routes/api.php,所以你不会得到任何会话值(这里是Auth)。
要获取值,请使用PassportHelpful link
或使用JWT

相关问题