Skip to content

faustoq/laravel-model-encrypt-fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Model Encrypt Fields

Encrypt and decrypt Laravel model fields

Installation

composer require faustoq/laravel-model-encrypt-fields

Note: The package will be autoregistered thanks to the Laravel Package Auto-Discovery.

Publish the configuration file:

php artisan vendor:publish --provider="ModelEncryptFields\ServiceProvider"

Usage

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use ModelEncryptFields\EncryptsAttributes;

class User extends Model
{
    // Add EncryptAttributes trait
    use EncryptsAttributes;

    // List of fields that should be encrypted in your database
    protected $encrypts = [
        'email',
        'name',
    ];
}

That's it! Now you can automatically encrypt/decrypt the fields specified in the $encrypts property in your model.

Examples:

Auto-Encrypt the field name:

$user->name = "John Doe";
$user->save();

Auto-Decrypt the field name:

echo "Hello, " . $user->name;

About

Simple crypt / decrypt for Laravel eloquent models fields

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages