I have a laravel project that already been running in production but now I want to encrypt confidential data which is salary column, here is the example of my table
|id|username|email|salary| |1|xxx|xxx@gmail.com|1000| |2|yyy|yyy@gmail.com|2000|
I want to use laravel encryption , so how to update my existing table and continue using laravel encryption
Advertisement
Answer
Instead of running any query into the database I’d prefer to execute this:
$users = AppUser::all(); foreach ($users as $user) { $user->salary = encrypt($user->salary) $user->save(); }
You’ll need to add a migration to the project in order to change the salary
type field to text