Paengski
Paengski

Reputation: 349

Encrypt ID in the URL using Laravel 4

I am new to Laravel 4, and I am trying to develop a simple employee CRUD system.

If I want to update a record, I have to access "domain/laravel/employee/1" it means that "1" represents as employee ID. Is there a function in Laravel 4 that I can set to encrypt the ID automatically?

Or maybe there is a better way instead of ID encryption?

Upvotes: 0

Views: 2434

Answers (2)

Piyush Kacha
Piyush Kacha

Reputation: 1

For that purpose you have to follow 2 steps

  1. encrypt id in blade file <a href="/product/{{ encrypt($product->id) }}">Delete</a>

  2. decrypt id in controller or web.php file $decrypted_id = decrypt($id);

Upvotes: 0

Sriraman
Sriraman

Reputation: 7947

It is not the best practice. If you encrypt the id using Crypt::encrypt($id), then the url will be

domain/laravel/employee/eyJpdiI6IjltdEJraDN3SWdGa21hTktodWdq

This is not easily predictable. Use Crypt::decrypt($id) to decrypt the id.

Upvotes: 1

Related Questions