PHPackages                             artistan/zero-nullable-dates - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. artistan/zero-nullable-dates

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

artistan/zero-nullable-dates
============================

Allows having zero date models in laravel

v2.0.2(6y ago)0411GPL-3.0-or-laterPHPPHP &gt;=7.0

Since Aug 13Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Artistan/zero-nullable-dates)[ Packagist](https://packagist.org/packages/artistan/zero-nullable-dates)[ Docs](https://github.com/Artistan/zero-nullable-dates)[ RSS](/packages/artistan-zero-nullable-dates/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

ZNDCarbon
---------

[](#zndcarbon)

Laravel Models with nullable carbon dates, this also allow for returning a date object. When the value is null/zeros that will format to ''.

### example

[](#example)

```
	// my_date on new model is null...
	// this will just be null value
	// so you can use the null coalesce operator to set a string

	echo $user->my_date->format('Y-m-d H:i:s') ?? 'Set a Date';

```

This is useful for old databases that do not have NO\_ZERO\_IN\_DATE, NO\_ZERO\_DATE so they may have 0000-00-00 type dates.

Add ZNDTrait and a couple arrays to define nullable dates to allow for zero and nullable dates.

You may also set null\_all\_dates on your model to set all to nullable without the arrays

Ultimately you can just set them all to `$nullable`, the addition of `$zero_datetime` and `$zero_date` are for testing that the database is updating as expected.

```
use Artistan\ZeroNullDates\ZNDTrait;

/**
 *  @see tests/Database/ZeroNullableUser.php
 */
class ZeroNullableUser extends Authenticatable
{
    use Notifiable;
    use ZNDTrait;

    /**
     * The attributes that are zero-datetimes
     *
     * @var array
     */
    public static $zero_datetime = [
        'created_date',
    ];

    /**
     * The attributes that are zero-dates
     *
     * @var array
     */
    public static $zero_date = [
        'created_date_time',
        'created_date_time_zoned',
    ];

    /**
     * The attributes that are nullable dates
     *
     * @var array
     */
    public static $nullable = [
        'created_date_time_null',
        'created_date_time_zoned_null',
        'created_date_null',
        'created_at',
        'updated_at',
    ];
}
```

The unit tests are dynamic and test 288 assertions

test for all combinations of what things are set for date columns.... all combinations of mutators, castings, and dates

mutatorcastdatexxxxxxxxxxxxnotes on current laravel functionality dealing with toArray, attribute accessors, and dates

\#toArray vs accessor

if you use $model-&gt;{camel\_key} (getAttributeValue), then it will
--------------------------------------------------------------------

[](#if-you-use-model-camel_key-getattributevalue-then-it-will)

- model-&gt;{key} &gt; getAttribute(key) &gt; getAttributeFromArray(key)
    - get the original attribute
- mutate : if hasGetMutator &gt; mutateAttribute
    - this is the accessor get{CasedKey}Attribute
    - mutate it if there is a mutator RETURN IT HERE
- cast : if hasCast &gt; castAttribute
    - cast it if there is a cast method RETURN IT HERE
- date format : if matches getDates &gt; asDateTime
    - finaly make a date (carbon) object from it `IF NOT NULL` RETURN IT HERE
- return value

note: the appends variables ARE mutated attributes that do not exist in the model attributes...

if you get attributes via $model-&gt;toArray then it will
---------------------------------------------------------

[](#if-you-get-attributes-via-model-toarray-then-it-will)

- addDateAttributesToArray via getArrayableAttributes
    - so this is cast to a string AFTER carbon dating, no other processing will be applied
- addMutatedAttributesToArray via getMutatedAttributes
    - so AFTER dates transformed from carbon, then it will try mutating the formated data
    - can mutate the already "date formated" data since it passes that value to the `mutateAttribute`
- addCastAttributesToArray
    - this will cast a value to whatever type is specified
    - if date it will serialize it to the format specified
    - note, this is AFTER dates have already been carbon dated and formated by mutator
- getArrayableAppends
    - this will add any mutators that are not directly related to a model attibutue

date mutators.
--------------

[](#date-mutators)

these are both mutators and accessors, or mutates in and out

- get from db sends us a carbon date

data analysis
-------------

[](#data-analysis)

when date keys are set for dates that allow ZERO dates the formatting for 000-00-00 or variations of that fail. `-0001-11-30 00:00:00` is the default result...

ZNDCarbon
---------

[](#zndcarbon-1)

using NULL as the data point when it is a zero nullable date

```
private static $empty_date = ['0', 0, false, '', '0000-00-00', '0000-00-00 00:00:00'];

```

### mysql mode

[](#mysql-mode)

`mysql`

```
SELECT @@sql_mode
```

### homestead box setup for testing

[](#homestead-box-setup-for-testing)

`vim /etc/mysql/mysql.conf.d/mysqld.cnf`

```
sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

```

### notes on dev package setup

[](#notes-on-dev-package-setup)

- example package
- package setup
- test setup
- .env file in tests directory for configuration of your tests
- `ln -s vendor/laravel/laravel/config` in tests directory to allow access to config files
    - laravel does not have a seperate "config" path from the base path, damn it.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~96 days

Total

5

Last Release

2445d ago

Major Versions

v1.1.0 → v2.0.02018-10-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/fc511d79233a52b0bb85db90dcac069b3482399e1a6778acfd1825092a2de9cb?d=identicon)[Artistan](/maintainers/Artistan)

---

Top Contributors

[![Artistan](https://avatars.githubusercontent.com/u/801349?v=4)](https://github.com/Artistan "Artistan (1 commits)")

---

Tags

laravelmodeldateszeronullable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/artistan-zero-nullable-dates/health.svg)

```
[![Health](https://phpackages.com/badges/artistan-zero-nullable-dates/health.svg)](https://phpackages.com/packages/artistan-zero-nullable-dates)
```

###  Alternatives

[gbrock/laravel-table

Table functionality for Laravel models

7644.3k](/packages/gbrock-laravel-table)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
