Closed ndollem closed 4 years ago
routes/web.php
:
Route::get('c/{cSlug}/{aSlug}', ['as' => 'article', 'uses' => 'PageController@getArticle']);
app/Http/Controllers/Application/PageController.php
:
public function getArticle(Category $category, Article $article)
app/Providers/RouteServiceProvider
:
Route::bind('aSlug', function ($slug) {
return Article::with('category')->where('slug', $slug)->firstOrFail();
});
Route::bind('cSlug', function ($slug) {
return Category::with('articles')->where('slug', $slug)->firstOrFail();
});
Great work you have here...
I'd like to ask on how to create routing if I want to make a pretty url. Something like this
where "fashion" is the slug for categories and "10-best-winter-coath" is slug for article. Since your routing only take 1 paramater, I dont know how to do it using 2 parameters.
I try some combination like this
But it didn't work
I'm new to laravel, so I hope you can help me how to work it out.