首页 > laravel 自定义服务,如何实现注入依赖?

laravel 自定义服务,如何实现注入依赖?

  1. 通过ServiceContainer, ServiceProvider, 建立了一个自定义的服务,请问如何在服务中使用依赖注入,比如 Request, User,Cookie等

如果直接在服务的方法中写入User $user ,提示如下:

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


没引入?
use App\User

【热门文章】
【热门文章】