0
I have a route that when accessing www.exemplo.com/comer
returns a view with the content.
What I’m trying to do now and created another route to do the same effect but when I try to access www.exemplo.com/cesar-Sousa does not return me the right view returns the view of the first example I gave above.
Basically I want to know how I can create Routes to access several different views but with the position of the domain always equal.
Example
www.exemplo.com/comer ->EstabelecimentosController@estabelecimentos
www.exemplo.com/cesar-sousa -> PerfilUserController@perfil_user
I want something like that same position always following the bar but depending on changing the Lug that is stored in the database return the right controller and the right view.
Routes
Route::get('{slug_user_perfil}', 'PerfilUserController@perfil_user');
Route::get('{slug_categoria}', 'EstabelecimentosController@estabelecimentos');
And more or less this I have the slugs stored in the database I intend that depending on the Slug displayed in the URL he knows which controller to use and by itself will return the correct view by I put two Routes with Slug parameter but when I try to access Slug of the users it always returns the controller of the categories that returns the view of the categories and this is my problem
I think so, this is an error... If Voce put the name instead of the variable solves the problem....
– novic
But I can’t put the name because Slug is stored in the database so that’s why I’m using variable what I intend is which way to make each Slug that returns in the URL it knows which controller it has to use
– César Sousa
It’s the following you put
Route::get('{slug_user_perfil}', 'PerfilUserController@perfil_user');
two equal routes only that point to different places, and this can not! if you can do different type:Route::get('comer', 'PerfilUserController@perfil_user');
andRoute::get('cesar-souza', 'EstabelecimentosController@estabelecimentos');
with are no variables will work as valid routes ... what you are trying to do will give crash routes and this can not and variable on root route is not a good practice, because it limits always be like this and can confuse the route systems as it already happens.– novic
But it has to be by variable because these names are slugs stored in the database there has to be a way around this because imagine that I have 100 users I will not make 100 routes to home user I think does not make sense
– César Sousa