Roberto.f.s
Roberto.f.s

Reputation: 3

How to encrypt a column value on an already filled table with unencrypted data in an existing laravel projects?

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|[email protected]|1000|
|2|yyy|[email protected]|2000|

I want to use laravel encryption , so how to update my existing table and continue using laravel encryption

Upvotes: 0

Views: 1161

Answers (1)

Professor
Professor

Reputation: 908

Instead of running any query into the database I'd prefer to execute this:

$users = App\User::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

Upvotes: 1

Related Questions