search

Home  >  Q&A  >  body text

Laravel custom service, how to inject dependencies?

  1. A custom service has been established through ServiceContainer and ServiceProvider. How to use dependency injection in the service, such as Request, User, Cookie, etc.

If you write User $user directly in the service method, the prompt is as follows:

Argument 1 passed to App\Services\UserService::register() must be an instance of App\User, none given, called in /home/vagrant/Code/zhicheauto/car-server/app/Api /Controllers/UsersController.php on line 32 and defined

我想大声告诉你我想大声告诉你2847 days ago545

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-16 16:55:06

    Not introduced?
    use AppUser

    reply
    0
  • Cancelreply