Laravel Useful Casts is a simple package for Laravel 7.0+ that comes with already-tested and already-written, useful casts for Eloquent models.
If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with Github Sponsors. 📦
You can install the package via composer:
composer require renoki-co/laravel-useful-casts
use RenokiCo\UsefulCasts\Casts\Encrypted;
class User extends Model
{
protected $casts = [
'ssn' => Encrypted::class,
];
}
// 'ssn' value gets encrypted in the database.
$user->update(['ssn' => '12345678']);
Cast class | Purpose |
---|---|
RenokiCo\UsefulCasts\Casts\Encrypted::class |
Encrypts and decrypts a value from the database |
RenokiCo\UsefulCasts\Casts\Arrayed::class |
Serializes and unserialies an array. If the value is null, returns an empty array. |
RenokiCo\UsefulCasts\Casts\EncryptedArray::class |
Encrypts and decrypts a value from the database, making sure it's always an array, even if the value is set or get as null |
vendor/bin/phpunit
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.