Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmedmessi's avatar

Auth::user() return null on livewire

I'm working on multi-step form and when I try to submit the form the Auth::user() returns null. I only encountered this problem when I deployed my application on my server

$rdv = Appointment::create([
  'code' => (string) Str::uuid(),
  'centres' => $this->centres,
  'date' => $this->date_rdv,
  'heure' => $this->heure_rdv,
  'status' => "Pending",
  'client_id' => Auth::id(),
  'appointment_type_id' => 1
]);
0 likes
5 replies
Sinnbeck's avatar

It's really hard to guess based on that tiny bit of code. Does the session work in other places? What session driver are you using in production? Did you try changing it?

aghorbanmehr's avatar

I found the fix you must mount the parameters that you need In your Livewire Component!

public function mount()
    {
        $this->user_id = auth()->id();
    }
ollie_123's avatar

Hi @ahmedmessi

It looks like you're calling Auth but not calling the user object like this... Auth::user().

 'client_id' => Auth::id(), 
// should be
 'client_id' => \Auth::user()->id,

If your calling Auth in your component, you either need to import it at the top of your component like use Auth;

OR

you can call it inline like this \Auth::user()->id.

ollie_123's avatar

Hey @Snapey. Awesome, i wasnt aware of that. I thought you always had to call the user object.

Please or to participate in this conversation.