phplaravelanalyzer

How to solve Laravel URL in a loop problem?


I have a category URL like this :

example.com/shop/category-name

And this is my web.php :

/* Categories Route */
Route::any('shop/{slug}', 'CategoryController@category')->name('category');

But when I analyze my website, I have this /shop in all of the URLs (Routes) :

analyze image

Why I have this /shop in all of routes ? Tell me if you want details Thanks.


Solution

  • Put a / before your shop so you make sure the route starts from the right place (or any other one that fits you, slash meaning home) :

    Route::any('/shop/{slug}', 'CategoryController@category')->name('category');
    
    

    With your syntax, you're basically telling laravel that any url with "shop/{something}" contained in it redirects to the @category method.