How to encrypt laravel 5.2 URL or Routes?

后端 未结 7 835
情歌与酒
情歌与酒 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:17

    You can encrypt the route in your controller while redirecting, using

    \Crypt::encrypt(product_id)

    and on the product page you can decrypt the product ID from the URL using

    $product_id = \Crypt::decrypt($url_parameter)

    that's the best possible way.

    But there will be some chances of exception if the user Edit's the Product ID parameter from the URL which you will need to handle.

提交回复
热议问题