Skip to content
Advertisement

How to encrypt id in URL laravel

I want to encrypt the id in URL I’ll show my controller code and route. I’ve already used Crypt::encrypt($id); in my controller but it’s not working properly so I’ve commented that line in my controller

this is my controller

JavaScript

this is my route

JavaScript

this is my blade

JavaScript

Advertisement

Answer

Use laravel builtin encryption to achieve this:

While adding your route in frontend, encrypt id with encryption helper like this:

JavaScript

Now, In your controller, decrypt the id you have passed.

JavaScript

I hope you understand.

Here is the docs:

https://laravel.com/docs/6.x/helpers#method-encrypt

https://laravel.com/docs/6.x/helpers#method-decrypt

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement