0

I have a problem to access Authenticate user in app service provider, here is my code. In cart Class (it's a custom class), I don't have access to current User. How can I access to Current user in custom Class?

public function register()
{
   $this->app->singleton(Cart::class,function($app) {
       return new Cart($app->auth->user());
   });
}
Bappi Saha
  • 404
  • 4
  • 10
Sally p
  • 23
  • 8
  • Welcome to SO ... if you try to resolve this `Cart` class before the `StartSession` middleware runs you will not have access to the 'session' which is what the default authentication system uses for authentication. also you probably want `$app->auth->user()` or `$app['auth']->user()` as there is not an `auth` method on `Application` – lagbox Sep 06 '20 at 05:30
  • 1
    A similar question has already been answered. This may help you: https://stackoverflow.com/a/37373424/10602851 – Ask17 Sep 06 '20 at 05:36

0 Answers0