2017 © Pedro Peláez
 

library laravel-encryptable-trait

Laravel encryptable trait, easily make certain fields for eloquent models encryptable

image

hihaho/laravel-encryptable-trait

Laravel encryptable trait, easily make certain fields for eloquent models encryptable

  • Wednesday, May 2, 2018
  • by RobertBoes
  • Repository
  • 3 Watchers
  • 2 Stars
  • 790 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 128 % Grown

The README.md

Laravel Encryptable Trait

License, (*1)

[!WARNING], (*2)

No longer maintained

We no longer use this package and will not maintain it. Please feel free to fork it and maintain it yourself., (*3)

Consider migrating to Laravel encryption features which we added since this package was created., (*4)

This package uses serialized encryption, while the Laravel encryption casts unserialized encryption. You can upgrade uses of this package to custom casts, e.g. by implementing Illuminate\Contracts\Database\Eloquent\Castable on a data object used as cast., (*5)


Introduction

This trait encrypts all your fields (defined in $this->encryptable) before saving it to the database. It makes it extremely easy to treat certain fields as encryptable by automatically encrypting and decrypting the values., (*6)

Install

Simply add the following line to your composer.json and run composer update, (*7)

"hihaho/laravel-encryptable-trait": "^v4.0"

Or use composer to add it with the following command, (*8)

composer require hihaho/laravel-encryptable-trait

Requirements

  • illuminate/encryption ^10.0 or ^11.0
  • PHP 8.1, 8.2 or 8.3

Usage

Simply add the trait to your models and set the $encryptable to an array of values that need to be encrypted., (*9)

<?php

namespace app\Models;

use Illuminate\Database\Eloquent\Model as Eloquent;
use HiHaHo\EncryptableTrait\Encryptable;

class Phone extends Eloquent
{
    use Encryptable;

    protected $encryptable = [
        'imei',
    ];
}

DecryptException

This package will throw a DecryptException (the default Laravel one: Illuminate\Contracts\Encryption\DecryptException). You can however set $dontThrowDecryptException to true to ignore the exception. If the value can't be decrypted it will just return null., (*10)

<?php

namespace app\Models;

use Illuminate\Database\Eloquent\Model as Eloquent;
use HiHaHo\EncryptableTrait\Encryptable;

class Phone extends Eloquent
{
    use Encryptable;

    protected $encryptable = [
        'imei',
    ];

    protected $dontThrowDecryptException = true;
}

If the database contains an invalid value, this will return null., (*11)

$phone = Phone::find(1);
$phone->imei; //Will return null

Contributors

The Versions

02/05 2018

dev-master

9999999-dev

Laravel encryptable trait, easily make certain fields for eloquent models encryptable

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mart de Graaf

laravel eloquent model encryptable

29/04 2018

dev-Laravel-5.6-support-readme

dev-Laravel-5.6-support-readme

Laravel encryptable trait, easily make certain fields for eloquent models encryptable

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mart de Graaf

laravel eloquent model encryptable

26/02 2018

v1.1.0

1.1.0.0

Laravel encryptable trait, easily make certain fields for eloquent models encryptable

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mart de Graaf

laravel eloquent model encryptable

18/09 2017

dev-analysis-qMxbO3

dev-analysis-qMxbO3

Laravel encryptable trait, easily make certain fields for eloquent models encryptable

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mart de Graaf

laravel eloquent model encryptable

12/09 2017

v1.0.1

1.0.1.0

Laravel encryptable trait, easily make certain fields for eloquent models encryptable

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mart de Graaf

laravel eloquent model encryptable

12/09 2017

v1.0.0

1.0.0.0

Laravel encryptable trait, easily make certain fields for eloquent models encryptable

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mart de Graaf

laravel eloquent model encryptable