Ad
Create Dynamic Routes In Laravel
I'm working on ecommerce website, Stuck in nav bar, I have created routes something like this:
Route::get('/category/{slug}', 'Site\[email protected]')->name('category.show');
In slug i pass slug of Product,
but i want to change something like this
Route::get('/{slug}/{slug}', 'Site\[email protected]')->name('category.show');
i want to remove category prefix and pass main category slug as a first parameter and sub category if it exist as a second parameter otherwise it will be empty.
One more thing i am using TypiCMS, for creating Nestable menu and it is working will i have to modify that also to work with the dynamic route.
Ad
Answer
Sorry I don't know anything about your cms framework but in Laravel you cant use the same name for two bindings in your route, they must each be unique.
Route::get('/{categoyrySlug}/{subcategorySlug}', 'Site\[email protected]')->name('category.show');
And in Site\CategoryController
you should be able to use :
public function show($categorySlug, $subcategorySlug){
...
}
and then handle them accodingly.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad