0
votes

I've made laravel e-commerce where i have like 100+ different kind of routes and there is no function in my web.php file all functions provided in controllers.

The issue I'm facing is every once a while one of my routes stop functioning and redirect me to whoops, looks like something went wrong page.

To fix that i have to move that route in top of my web.php file and then it works.

Result of that will be other route will brake this time!

It is impossible for me to change routes positions every second!!

How can i fix this issue? Any experience?

Update

As i checked my log file, for my back-end (admin panel) that error caused because I've made my title unique and couldn't make double of same title fixed.

In other hand for my front-end i do not have any sort of same url is just getting unique urls like domain.co/products and i only have one route like that but it gave whoops error and i must move it to the top of my route lists, why is that?

2
Have you checked any logs? Post those details in the question - DsRaj
We’re going to need to see the code to help you – you’re going to need to post all of the parts you’re talking about, and turn on debugging so you don’t just get a ‘Whoops’ error. - Zoe Edwards
@ThomasEdwards I'm trying to make new log file to share results please be patient. - mafortis
Enable the debug in your config file to see a real error. - Dessauges Antoine
first of all post your web.php file. - Parth Pandya

2 Answers

1
votes

This is a common problem actually it happens because one of your routes is overriding another route check explanation below

lets say you have two closure based routes

Route::get('hello/{name}' , function($name){
    return "hello " . $name;
});

Route::get('hello/world' , function(){
    return "hello world is working"; 
});

as you can see in the example above I have my first route accepts a route parameter and it will output hello plus the name passed in the route

for example you visit /hello/mohammad that will output "hello mohammad"

but only in the second route you want if someone visit hello/world the text "hello world is working" to be returned ;however, hello world is returned.

this happens because we defined the route that accepts parameter before the static route (/hello/world) so just if we reverse the orders of route it will work as intended.

so one rule to keep in mind when ever defining two routes that starts with same path (in our case they both starts with hello) always define the static route before the dynamic route.

That's why it's also a good idea to group your routes that starts with the same prefix

Hope you get it and found my explanation helpful.

I suggest that you read more about routing in Laravel documentation

https://laravel.com/docs/5.6/routing

0
votes

if you have 2 routes with same address change them and for more help please send us your web.php file