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
Asked
Active
Viewed 43 times
-1
-
can you screen your codes? – Samandar May 22 '21 at 05:41
-
which code you want to see then i edit in this question and if you want to see all code then i posted on my git repo https://github.com/parthkapatel/movie-ticket-booking-system – Parth KaPatel May 22 '21 at 05:43
2 Answers
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();
![](../../users/profiles/10400380.webp)
Abdul Rehman
- 21
- 3
0
try this
auth('api')->user()->id
![](../../users/profiles/10801344.webp)
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