This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Convert 0000-00-00 dates in the database to null when accessing your model's attributes.

v1.0 2019-09-04 05:42 UTC

This package is auto-updated.

Last update: 2021-07-04 10:27:40 UTC


Scrutinizer Code Quality Code Coverage Build Status Total Downloads Latest Stable Version License

Eloquent Empty Date Nullifier

Little trait to convert "0000-00-00" dates in the database to null when you access them using Eloquent models, useful when you have to deal with (legacy) polluted data.


composer require joskolenberg/eloquent-empty-date-nullifier


Add the JosKolenberg\EloquentEmptyDateNullifier\NullifiesEmptyDates trait to your model, and all your 0000-00-00 dates will be converted to null when accessing them using your eloquent model and during serialization.

use Illuminate\Database\Eloquent\Model;
use JosKolenberg\EloquentEmptyDateNullifier\NullifiesEmptyDates;

class Person extends Model
    use NullifiesEmptyDates;

    protected $dates = [


$person = new Person();

	'date_of_birth' => '0000-00-00',

$person->date_of_birth; // = null


"0000-00-00" dates can be present in a database when empty values are stored but the column is not set to be nullable. The recommended approach is to make the column nullable and convert all the empty values to null in the database. However, this might not always be possible e.g. when other (external) applications rely on the same data. In that case this package may come in handy.

That's it! Any suggestions or issues? Please contact me!

Happy coding!

Jos Kolenberg