dimanche 12 janvier 2020

Laravel middleware api always return null even with the correct token

I just use the default api that laravel provided with a little change when i make the project which is

    Route::middleware('auth:api')->get('/user', function (Request $request) {
    return User::all();
});

I already make api_token in user table and fill it with some token When i use postman the api works Postman

But when i write the request code in the controller it always return null

$token = 'abcde';
$request = Request::create('/api/user', 'GET', [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
]);
$response = json_decode(Route::dispatch($request)->getContent());
dd($response);

The api works if i dont use middleware('auth:api') Any suggestion?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire