Support the ongoing development of Laravel.io →
Requests IOC
Last updated 3 weeks ago.
0

In that example, ArticleForm is used to handle any non-GET request. If there's a GET request, I simply pull the data from the Article/Status repositories.

EloquentArticle and EloquentStatus are needed to accomplish that. I don't "re-use" $this->articleform->article because that's bleed dependencies from the articleform into the controller. If I changed articleform, then the controller would be affected in places where articleform isn't even really used, other than to grab the "article" repository.

It's also very much about making intent clear rather than any over-arching coding principle (other than "clean code" I suppose). It's more explicit to inject dependencies "again", if if they happen to be available via another "injected dependency".

I inject those directly into the controller since it's easier. If I wanted to "protect" my application layer from the HTTP layer (make is so controllers had no knowledge of repositories, etc), I'd probably re-factor my app to have "scenarios", "commands" or "uses cases" in which each scenario has a class (Create new article, get specific article, update article, would each have their own injected dependencies (yes, even if they are available somewhere else).

Overall I'm favoring everything being explicit. I'm avoiding sharing resources (bleeding dependencies). Change it to suit your needs and opinions tho! We're all allowed to code things differently and have different opinions :D

Last updated 3 weeks ago.
0

In fact I've come up with the same solution (the "double injection"). However, it seemed a little bit of strange to me and I thought I'd pause and look and what other developers are doing. Then I found yours... :D

But yes, the change part totally makes sense. I probably won't handle it very differently, as I said it's also that what I've come up with, I was just wondering if there is a more elegant way. Having the model twice adds overhead. But I guess there is no good way around it.

Thanks for your reply.

Last updated 3 weeks ago.
0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Langdi Langdi langdi Joined 6 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.