In a Service Provider register
method we can bind an interface to an implementation:
public function register()
{
App::bind( UserRepositoryInterface::class, EloquentUserRepository::class );
}
From now on, everytime the app will need an instance of UserRepositoryInterface
, Laravel will auto inject a new instance of EloquentUserRepository
:
//this will get back an instance of EloquentUserRepository
$repo = App::make( UserRepositoryInterface:class );