Reputation: 307
I have a project like amazon based on Laravel 5.2.
I need to show title of product and category in URL of page which preview with only ID.
For example:
ID: 2
Name: Apple iPhone 6s
The URL: www.mysite.com/showproduct/2
I need this to be: www.mysite.com/showproduct/2-Apple-IPhone-6s
Upvotes: 1
Views: 1356
Reputation: 67505
If you take a look to Laravel 5.2 documentation especially Route Parameters part, you will notice a red box there say :
Note: Route parameters cannot contain the - character. Use an underscore (_) instead.
So your route could be:
Route::get('showproduct/{title}', 'Controller@action');
But instead of 2-Apple-IPhone-6s
it should be 2_Apple_IPhone_6s
, IMO better if you could use it as:
Route::get('showproduct/{id}/{title?}', 'Controller@action');
Hope this helps.
Upvotes: 1
Reputation: 5004
Try this: https://github.com/cviebrock/eloquent-sluggable
Don't make the wheel again ;)
Upvotes: 0