-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[Bug] BindingResolutionException: Unresolvable dependency resolving #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You should bind the class to $app, try adding this to routes.php: App::bind('Project', 'Project'); or App::bind('Project', function() { return new Project; }); |
First solution didn't work (because I guess it's what Laravel does in the background by default anyway). Second one did. Thanks ! |
Looks like it ignores the fact that the |
You wouldn't inject an Eloquent object like that. It wouldn't make sense. Inject a repository or something else. There would no point in injecting a model. |
Well I'm not really trying to inject an Eloquent object, I'm trying to bind Eloquent as a repository — by using its query builder methods like you would use methods from a repository to fetch from the database. |
Yeah, I wouldn't suggest that. You need to write a real repository if you want to get the testability benefits. |
Anyways, this isn't really a "bug" per se. The IoC container needs to know what you want to inject because there is no type hint. I can probably improve the container to inject default arguments though. I believe Dan Horrigan added a pull for that. |
What do you mean by |
In the Model class. |
Oh okay :) |
I'm trying to use dependency injection as explained in the docs. My controller has the following construct :
And here is the Project model :
In my head this was supposed to work but somehow here is the Exception that is thrown :
Can't Eloquent models be injected automatically like this ?
The text was updated successfully, but these errors were encountered: