0

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
1
  • 1
    Could you please provide the way you implemented the custom class? Is the custom class included in the app container? If it does you should be able to use any facades without problems. Commented Oct 12, 2016 at 20:28

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

1 Comment

When I use this I get null
0

Try Auth::user(). This wil return a user object, so you can do Auth::user()->id or Auth::user()->email;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.