Hello everyone, tell me who knows how to get access to Auth :: user () in the service provider public function register() { $this->app->singleton(Cart::class, function () { return new Cart( new HybridStorage(Auth::user(), 'cart'), new DynamicCost(new SimpleCost()) ); }); } public function register() { $this->app->singleton(Cart::class, function () { return new Cart( new HybridStorage(Auth::user(), 'cart'), new DynamicCost(new SimpleCost()) ); }); }

Auth :: user () is always null, or there may be another way of binding the interface to the implementation.

  • The problem is that the service provider starts earlier than the user. Try to go in the direction of middleware - StereoFlo
  • And in middleware, can I create a singlet "$ this-> app-> singleton ()"? - Sasha Zaplitny

0