0
votes

I use passport for api authentication and i configure auth.php api gaurd to passport.
Some of my route APIs are in auth:api group. I send Authorization header with access token and it check user very well.
But the problem is that, this mechanism works well in Route::post method and \Auth::user()->id return user id,

but in Route::resource \Auth::user() returns null.

I double checked everything and it seems Route::resource ignore "auth:api" middleware. I also tested middleware in __construct method of my resource controller. Nothing changed. Thank you for further help.

Route::group(['middleware' => ['auth:api']],function (){
    Route::post('update',['uses'=>'C_Update@handle']);
    Route::resource('contacts','C_Contacts',['only'=>['index','store','update','destroy']]);
});
1
Route::resource literally isn't doing anything more than registering the 7 routes you could manually register.lagbox

1 Answers

0
votes

At last i found a solution. The problem was because of __construct method. The Authenticated user hasn't been Authorized in construct method yet (I don't know why and if someone knows please tell me). So unfortunately I put \Auth::user in CRUD functions of my route.