How to hide ID on routes laravel 5?


I have the following URL:

I would like to know if it is recommended that the user's ID appear in the URL, or a URL such as:

Should the last option be better, how could it be done? modifying Route Route :: get a Route :: post?

asked by Juan Pablo B 03.11.2016 в 13:53

3 answers


If you want to hide the id, you can use a slug for each user, there is a "slugify" package that does that job very well and makes url look better, besides hiding how many id you can have in your database table.

If it is for security, that you use GET or POST will not influence much.

In this case the most appropriate verb is still GET, because you are not making any changes to the database, only obtaining data from it.

Finally, you should take advantage of the model binding offered by laravel directly on the route.

answered by 03.11.2016 / 14:02

If you want to change the database column that is used for the Model Binding , say, for example, for a token or some other unique field, from Laravel 5.2 , you can do it by adding this in your model:

public function getRouteKeyName(){
    return 'token';

Regarding using POST instead of GET , it's anti-standard ( RESTful ), GET it's just to obtain the resource (s), and POST to create or create them. I recommend you to see good practices:


answered by 12.11.2016 в 22:16

If what you want is for your URL to hide or hide the id, I recommend using Fakeids.

It will cause the ids to be masked in your URL, for example, instead of being shown to you by your url:

is going to show you something like this:

Much cleaner your URL than using Encrypt and everything done automatically.

documentation: link

answered by 30.07.2018 в 23:21