How to encrypt laravel 5.2 URL or Routes?

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

    You can encrypt your url parameter and decrypt it in your controller. You can try this:

    In your view: Suppose your parameter is id or more parameter you can encrypt.

    1,
            ];
        $parameter= Crypt::encrypt($parameter);
    ?>
    a link
    

    Your route will be:

    Route::get('/url/{parameter}', 'YourController@methodName');
    

    In your controller, You can decrypt your parameter:

    public function methodName($id){
        $data = Crypt::decrypt($id);
      }
    

    You must be yous Crypt namespace in your top of controller

    use Illuminate\Support\Facades\Crypt;
    

    Note: You can encrypt url parameter with Crypt::encrypt($parameter) and decrypt with Crypt::decrypt($parameter)

提交回复
热议问题