I am developing an application in the Laravel 5.2 which must have a friendly URL-s. This is not problem with the regular way, where the {slug} wildcard is handled by a controller but I want to make it in a different way.
For now I have only two controllers:
ProductsController@show
to show details productCategoriesController@show
to show selected category with listing products which are assigned to it
And routes:
Route::get('product/{product}', 'ProductsCategory@show')->name('product.show');
Route::get('category/{category}', 'CategoriesController@show')->name('category.show');
So when I want to echo a just use route('product.show', compact('product'))
Nothing special until I want to handle different URL-s which are fetched from a database. I thought it will be possible to make an another routes which are assigned to existing and when I use a route(...)
helper it will be handled automatically. But it is not. So for example I have a new URL:
domain.com/new-url-for-product.html
so by route it should be assigned to the regular 'product.show' route with some ID, which is handled by route model binder for {product} wildcard. The same for route(..)
helper it should print friendly URL-s.
I don't know if my strategy is good. How do you handle with the similar problems?