How to hide ID on routes laravel 5?

3

I have the following URL: domain.com/user/3/edit.

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

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
source

3 answers

4

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
source
3

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:

link

    
answered by 12.11.2016 в 22:16
0

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: -domain.com/user/3/edit.

is going to show you something like this: -domain.com/user/192849273/edit.

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

documentation: link

    
answered by 30.07.2018 в 23:21