@jordan-dev
i think the logic on every request is not very good, instead
/fruits/product/{product-slug}
/fruits/sub/{sub-category-slug}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have the task to create not ordinary URL structure for Laravel ecommerce project. URL for product: /category-slug/product-slug Example: /fruits/orange But Url for sub-category have the same structure: /category-slug/sub-category-slug Example: /fruits/citrus
My solution is:
Route( '/{category}/{var}' , function(Category $category, $var) {
if( $sub_category = SubCategory::where('slug', $var)->first() ) {
return view('sub-category')->with('sub_category', $sub_category );
}
if($product = Product::where('slug', $var)->first() ) {
return view('product')->with('product', $product);
}
abort(404);
});
But I dont like that we do extra request every time when visit product page. Maybe someone has already solved this problem, please provide your solution. Thanks in advance.
Please or to participate in this conversation.