Answer the question
In order to leave comments, you need to log in
Why can't Laravel inject the dependency?
Good day.
Created my daddy Contracts, which contains the DataSource interface. I expect an instance of DataSource in the controller method, but Laravel says that this class does not exist.
ReflectionException - Class App\Contracts\DataSource does not exist
public function register()
{
$this->app->bind('App\Contracts\DataSource', function ($app) {
return new App\DataSources\Source;
});
}
Answer the question
In order to leave comments, you need to log in
Before App try \ put
$this->app->bind('\App\Contracts\DataSource', function ($app) {
return new \App\DataSources\Source;
});
use App\Contracts\DataSource;
use App\DataSources\Source;
$this->app->bind(DataSource::class, function ($app) {
return new Source::class;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question