Answer the question
In order to leave comments, you need to log in
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 модели машины достал сами машины
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]']);
Answer the question
In order to leave comments, you need to log in
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
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?
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 questionAsk a Question
731 491 924 answers to any question