Im trying to leverage from the Implicit route model binding of laravel 5.2. I have a page that shows an article with its comments etc.
my routes are as follow:
Route::singularResourceParameters();
Route::group(['middleware' => 'web'], function () {
Route::group(['prefix' => 'blog', 'namespace' => 'Guest'], function()
{
Route::bind('article', function ($value) {
return App\Models\Article::with('user')->with('channel')->with('comments')->find($value);
});
Route::resource('articles', 'ArticlesController');
});
});
and in my controller I have this:
class ArticlesController extends Controller
{
public function show(Article $article)
{
return view('guest.articles.show', ['article' => $article]);
}
public function getEdit(Article $article)
{
return view('guest.articles.edit', ['article' => $article]);
}
}
The problem is that as you can see i specified a custom way I want the article to be resolved before passing it to the controller, because I needed the comments, channel, and user relationships eager loaded just for the show() method since that displays the article with all that information, but when I want to edit the article or any other method, I don't need all those eager loaded relationships, how can I specify that I want that custom resolve only for the show() method?