Laravel5 dependency injection on Model

前端 未结 2 1809
深忆病人
深忆病人 2021-02-13 15:10

I have an Eloquent Model called Surface which is dependent on a ZipCodeRepository object:

class Surface extends Model{
    public function __construct(ZipCodeRep         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-13 15:36

    In Laravel 5.7 you can use the global resolve(...) method. I don't think the global App is defined in more recent version of Laravel.

    $myService = resolve(ServiceName::class);
    

    Resolving in Laravel docs

提交回复
热议问题