The problem here is these are all the same routes. Laravel doesn't know what would count as a categorie, shopname, or any. For example if I go to /products/test
, Laravel won't know if test is a categorie, a shopname, or a name of a product.
Try this instead...
Route::group(array('prefix' => 'products'), function()
{
Route::get('/', array('uses'=>'products@index'));
//show all the products
Route::get('categorie/{Categorie}',array('uses'=>'products@categorie'))->where('Categorie','^[A-Z][a-z0-9_-]{3,19}$');
//show the products of this categorie
Route::get('shopname/{shopname}',array('uses'=>'products@shopname'))->where('shopname','^[a- z][a-z0-9_-]{3,19}$');
//show the product of this shopname
Route::get('product/{productName}', array('uses'=>'product@getProduct'));
//the Product controller is now SINGULAR
});
This way, if I go to products/categorie/test
, Laravel will know that I'm looking for a categorie
and be able to route me appropriately.
Update:
If Hightech
is a category and product_1
is a product, you could use a route like this...
Route::get('category/{categorie}/product/{product}',array('uses'=>'products@categorie'))->where('categorie','^[A-Z][a-z0-9_-]{3,19}$')->where('product','^[A-Z][a-z0-9_-]{3,19}$');
//show the products of this categorie
And then the URL would be .com/products/category/Hightech/product/product_1
. Or you can take the /product
out and /category
out and you could just go to .com/products/Hightech/product_1