Level 75
No everything is ok, because you want to have category and subcategory in the url.
For me will be maybe better to have two separated controllers for that. And subCategory has optional in the route.
Route::get('{category:slug}/{subCategory:slug}/{product:slug}', 'ProductController@show');
Route::get('{category:slug}/{subCategory:slug?}', 'CategoryController@show');
class CategoryController extends Controller
{
public function show(Category $category, Category $subCategory = null)
{
$category = $subCategory ?? $category;
return view('category.show', compact('category'));
}
}
1 like