Download the PHP package mr-feek/eloquent-null-casts without Composer
On this page you can find all versions of the php package mr-feek/eloquent-null-casts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mr-feek/eloquent-null-casts
More information about mr-feek/eloquent-null-casts
Files in mr-feek/eloquent-null-casts
Package eloquent-null-casts
Short Description Model attributes that are null will be cast if they are listed in the casts array. Unlike default Eloquent.
License MIT
Homepage https://github.com/mr-feek/eloquent-null-casts
Informations about the package eloquent-null-casts
Allow eloquent to cast null values of attributes
By default, Laravel does not allow casting null values of attributes listed in the casts
array. This isn't always desirable,
as sometimes you want to ensure an attribute is always a boolean. This package provides a simple trait to override this behavior on a
per Model basis. It isn't always feasible to run a migration to no longer allow null in the database.
Installation
You can install the package via composer:
Usage
In PHP we cannot override a trait's property in the class where the trait is used, so we have two implementation choices.
First option is to use the CastsNullAttributes
trait and define the casts in the constructor.
The other option is to use inheritance to implement the CastsNullAtrributes
trait, and continue defining the casts
inline as you would typically with Eloquent.
In both of these cases, if the actual value of deleted
is null, it will actually be cast to a boolean (false) to satisfy later typehints.
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Fiachra McDermott
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
All versions of eloquent-null-casts with dependencies
illuminate/database Version ^5.8|^6.0|^7.0
illuminate/support Version ^5.8|^6.0|^7.0