How to encrypt laravel 5.2 URL or Routes?

后端 未结 7 832
情歌与酒
情歌与酒 2020-12-19 10:51

I need to encrypt routes in this URL? Because I do not want user to access URL by changing the item id. For example, user can change /items/1234 to /item/5678. Although item

7条回答
  •  再見小時候
    2020-12-19 11:05

    One way you could mitigate this issue would be to use Universally Unique ID's (UUID).

    You will no longer have the issue of auto-increment database crawling and a user cannot alter URL's to get different data.

    You can quite easily change your database to support this in your migrations by changing your id column from

    this:

    $table->increments('id');
    

    to this:

    $table->uuid('id')->primary();
    

    Your model can then be edited to support the non incrementing primary key by adding the following to your class:

    protected $incrementing = false;
    

提交回复
热议问题