F
F
Fet2016-01-04 16:55:03
Laravel
Fet, 2016-01-04 16:55:03

Routing in Laravel 5. How to get rid of id in links?

Good afternoon.
I have a catalog of cars.
From the main page to the final one, I always pass id (brands, models, cars) by which I then get the necessary elements from the database.
Routes look like this:

Route::get('catalog/cars-for-parts', ['as' => 'catalog.auto_brands', 'uses' => '[email protected]_brands']); //главная каталога
Route::get('catalog/cars-for-parts/{id}/models', ['as' => 'catalog.auto_models', 'uses' => '[email protected]_models']); //по id марки достал модели машин из базы
Route::get('catalog/cars-for-parts/models/{id}/cars', ['as' => 'catalog.carkits', 'uses' => '[email protected]']); // по id модели машины достал сами машины

I want to make beautiful routes like
Route::get('catalog/cars_for_parts/{brand_name}', ['as' => 'catalog.auto_models', 'uses' => '[email protected]_models']);
Route::get('catalog/cars_for_parts/{brand_name}_{model_name}', ['as' => 'catalog.carkits', 'uses' => '[email protected]']);

But I don’t understand how to get cars and models (without id) in this situation?
Or is it possible to somehow pass the id without showing it in the route?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fet, 2016-02-01
@halenharper

I do not know how to be right here, how to mark the solution. I took D' Normalization's
advice as an answer .
Well, generate a slug for brand_name and model_name and store them in the database the same way.
I made a slug and I refer to them instead of id

D
D', 2016-01-04
@Denormalization

And what about Laravel?
What is brand_name and model_name? Are they in the database? Where do they come from?
If they are in the database, then what's the problem with getting data by model_name for example? How is this different from getting data by ID?

L
lynnikvadim, 2016-01-08
@lynnikvadim

Here is an example of how srouts worked in laravel 5.2
https://laracasts.com/series/whats-new-in-laravel-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question