I created custom class in Laravel and try to use object Auth():
But I can not get access to this object: Auth()->user()->id.
I tried to use:
use Illuminate\Support\Facades\Auth
I created custom class in Laravel and try to use object Auth():
But I can not get access to this object: Auth()->user()->id.
I tried to use:
use Illuminate\Support\Facades\Auth
When using Facades, you don't need to specify the whole namespace, just
use Auth;
Then, you should be able to use this in your custom class:
$user = Auth::user();
Alternatively, there is a globally-accessible auth() helper that you can use without the Facade at all:
$user = auth()->user();