Custom routes in Laravel 5.4?

0

For those who work with Laravel , they would know to inform me sources so I can search on how to create URL's clean and friendly so that I can pass a parameter, for example, category_name , or product_name , and the routes system recognizes and calls the corresponding view ?

Detail: I do not want to have to pass a prefix of type categoria/category_name , produto/product_name , because so I did the test and it works fine.

The idea is to get the value of the url, get to the database in the related tables and see which match gives it to decide if it is a category, a subcategory, a store, a product, I believe that the path is not this , even though Laravel tends to make everything simple, and so it is complex.

Thanks to anyone who can give me guidance on where to go, an article talking about it would already be of great help and a good start for me.     

asked by anonymous 13.04.2017 / 22:39

1 answer

-1

To retrieve some data from the URL, you can use a direct parameter in the route using a variable name in braces, like this:

Route::get('categoria/{categoria}', function($categoria) { return response($categoria); })

The result of this can be tested as follows, when entering: localhost:8000/categoria/carros , the value "cars" will be placed in the $categoria variable, which can be used anywhere. (In this example case, a response carros will print on the screen)

More details can be found in the documentation at Route Parameters .

    
13.04.2017 / 22:52