Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
How to get Auth::id() server-side on ajax post? It's returning null. Laravel 5.4

My user is authenticated.

To prove it:

axios.get('http://127.0.0.1:8000/api/user')
    .then(response => {
        console.log(response.data)
    })

...and the user info is logged to console as expected.

So experts, please tell me, how can I get Auth::id() on the server side on an ajax post??

Auth::id() returns null. It doesn't make sense that I would pass the user id with the data payload when the user is authenticated.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Every route going through api, by default you need to do

$id = Auth::guard('api')->id; //OR 

$user = Auth::guard('api')->user();
if ( $user ) $id = $user->id;

You could do it in one line

$id = Auth::guard('api')->user()->id;

But if the user fails, you will receive Cannot get property id of null

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!