Laravel : get user id in the api controller using Passport

Viewed 278

We are trying to retrieve the authentified user id on the api controller:

$user = auth('api')->id();
return FormulaireResource::collection(Formulaire::where('user_id', $user)->paginate(15));

the problem come from $user who's always NULL

here is the API.php:

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

We are generating users with token but not able to use them.

thanks for the feedback

0 Answers
Related