Laravel package to decrypt an Eloquent model or collection based on a variable set in the model class
This is a little laravel package which takes a collection or an Eloquent model and decrypts the fields of either every model in the collection which are defined in the $encryptable variable in your model(read below) or a model depending of what function you use, it returns the model or collection as an array, so it is mostly usable when wanting to return some json like if you are creating an API, all you need to do is encode it., (*1)
To install just add this to your composer.json "oleander29/decrypt": "dev-master"
then run composer update., (*2)
After this add the service provider to the config/app.php file like so Oleander29\Decrypt\DecryptServiceProvider::class
, (*3)
And lastly add an alias in the same file(config/app.php) like so 'Decrypt' => 'Oleander29\Decrypt\DecryptServiceFacade'
, (*4)
Remember to add a variable to your model so the package can see what fields it can decrypt and what it should not, you need to add the following variable:, (*5)
protected $encryptable = [
'field1',
'field2',
];
, (*6)
To use the decrypter and it's functions just add use Decrypt; on top of your file, and you can then use the following functions like so:, (*7)
Decrypt::collection($collection);
Decrypt::model($model);