-1

I am using laravel ui auth for login and register and all other features and CRUD operation for that i used VueJS and for CRUD operation i used laravel api.php route to access controllers function all the data are received but when i try to access Auth()->user()->id using api.php router then it will display this error " Trying to get property 'id' of non-object " but if i used same function using web.php route then it will sent me correct user login details

this is error but now it will display null value but if i used web.php route then sent me correct data

this is the code that i used for get user id

2 Answers2

0

If you have defined api guard then you can use simple method to get login user id from api side

auth('api')->id();

If its from web you can use simply

  auth()->id();
0

try this

auth('api')->user()->id
Samandar
  • 54
  • 5
  • I try this but not working i find the problems some website said that it problem occurs because of token that passed with api but i don't know how and i tried many solutions about token passed but didn't work anyone – Parth KaPatel May 22 '21 at 07:27