I'm moving a large project from CodeIgniter to Laravel 5, and am encountering a problem that I can't seem to find a solution for.
I know you can do route model binding, and I've been using it extensively without problem, and I know you can do method injection, such as injecting the Request into the method.
But my "problem" is I have multiple classes with the same name, but for different sections of the project, for example:
App\Models\Knowledgebase\Article
App\Models\News\Article
App\Models\Minisite\Resources\Article
As you can see, I have 3 different Article
models. One for Knowledgebase Articles, one for news articles and one for departmental resource articles.
However, with route model binding, it seems I can only bind one model to a keyword, and since my URLs each have the keyword Article, it doesn't really work.
So my question is, is it possible to inject the related model into the method by specifying it as a parameter? Or do I need to hard code it into the method by saying:
$article = App\Models\Knowledgebase\Article::find($some_id);
Or can I do something like this:
public function show(App\Models\Knowledgebase\Article $article)
{
// code
}
At the moment, if I try to inject the article, $article
becomes a new instance of the Article model, rather than the model record. It just seems a bit weird that the framework would make you manually retrieve the model for each method.
Any help is appreciated.