0

I am working on a new project that stores guest information. For security I thought it would be cool to store all the personal data in the database with encryption. Is there any specific workflow for doing this. Essentially setting encryption on certain Model fields and having everything just work. Thinking about it, I feel like its not so simple but I thought I would throw it out there.

2 Answers 2

2

This is actually quite straightforward in Laravel. All you have to make sure is that your accessors & mutators(for the properties that you want to encrypt) use the encryption.

More about accessors & mutators here : https://laravel.com/docs/5.6/eloquent-mutators

For example, if you want to encrypt the property email for your model, add the following:

//mutator
public function setEmailAttribute($value)
{

    $this->attributes['email'] = Crypt::encrypt($value);

}


//accessor

public function getNameFirstAttribute($value)
{
    if (is_null($value)) {

        return $value;

    }

    return Crypt::decrypt($value);
}
Sign up to request clarification or add additional context in comments.

2 Comments

i tried the same but got some errors not working this
hi i want his for whole columns and this will get lot of tome to work is there another solutions like protected $encryptable = [ 'first', 'last', 'email', ];
1

You can use accessors and mutators. They will encrypt data when you store the data and decrypt it when you fetch by itself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.