Search code examples
laravellaravel-routinglaravel-5.6laravel-authorization

How to use auth in api routes


I'm trying to call Auth::user() in my routes/api.php file.

But the Auth::user() returns null.

Meanwhile, as in the routes/web.php file it work.

How to fix it?

I will be grateful...


Solution

  • Call with guard()

    Auth::guard('api')->user();