PHP code example of artistan / zero-nullable-dates

1. Go to this page and download the library: Download artistan/zero-nullable-dates library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

artistan / zero-nullable-dates example snippets



	// 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';
	 


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',
    ];
}

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