I have a route like the following.
Route::get('/articles/{articleSlug}' ,
[App\Http\Controllers\ArticleController::class, 'single']);
And the method of single()
at ArticleController
class goes here:
public function single($slug)
{
$article = Article::where('slug',$slug)->first();
$article->increment('viewCount');
return view('home.article',compact('article'));
}
Now I wish to use Route Model Binding for finding this data from the articles
table based on the column slug
. But as I know, Route Model Binding finds data based on the id. So how to change Route Model Binding finding data from id
to slug
ONLY for ArticleController.php
(meaning that the other Controller classes can work with id as route model binding)?