Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda