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

piekuns18's avatar

Class hash does not exist

When i use Auth::user() in my AppServiceProvider class register function. I got this error: Class hash does not exist ?? Hoh can i resolw it? I hav 5.4 laravel

0 likes
5 replies
tykus's avatar

You don't want to be doing anything in the register method than relies on the entire app being bootstrapped; it is intended for binding classes into the container.

You should be able to use Auth in the boot() method.

Snapey's avatar

What @tykus says is correct. The register method is there for each service provider to do their own internal setup and binding into the app.

Since you don't know the order that all the service providers will be registered you cannot rely on anything at that point.

Once all the providers are registered, the boot method is called on each

piekuns18's avatar

Then maybe you could suggest something? I want register service only if user is administrator? Is it possible?

Please or to participate in this conversation.