Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

Login through API

I have below code in one of controller function which I am trying to access through API.

if (Auth::Check()) {
   //more code
} else {
  return response()->json([
     'message' => 'Please login',
     );
}

I used Bearer Token but I can't login.

enter image description here

0 likes
5 replies
afoysal's avatar

Thanks @silencebringer . I tried your solution Auth::check(). But it is not working. I sent Bearer Token with API request but it is not working.

shami003's avatar

You can use middleware api group, and you don't need Auth:check() then

Route::group(['middleware' => 'auth:api'], function(){
    Route::post('details', 'API\UserController@details');
});

Please or to participate in this conversation.