mardi 8 mars 2022

How to get current user when running command in laravel

I'm processing in the command line. And I want to get the current user, I use 2 ways to get it, but both return a result in Null

use Illuminate\Support\Facades\Auth;

public function handle()
{
   Auth::id(); //null
   // or
   auth()->user()->id //null
}

If I submit the form, using those 2 methods can get the current user, but when I run the command, I can't get it. Anyone give me any ideas to improve it. Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire