PHP code example of amrachraf6699 / datify

1. Go to this page and download the library: Download amrachraf6699/datify 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/ */

    

amrachraf6699 / datify example snippets


use Datify\Concerns\HasDatifyTimestamps;

class Model extends \Illuminate\Database\Eloquent\Model
{
    use HasDatifyTimestamps;
}

return [
    // Turn on extra accessors:
    'to_human' => true,
    'to_short_human' => true,
    'to_iso_8601' => true,
    'to_date_time' => true,

    // Custom naming (created_at.pretty, updated_at.pretty, etc.)
    'suffix' => '.{format}',

    // Custom format string (used when selecting 'custom')
    'custom' => 'd/m/Y H:i',

    // Default display for base attributes
    'defaults' => [
        'created_at' => 'to_human',
        'updated_at' => 'custom',
    ],
];

$post = Post::first();

$post->created_at;           // "2024-12-28 13:37:42"
$post->created_at_human;     // "2 hours ago"
$post->created_at_iso_8601;  // "2024-12-28T13:37:42+00:00"

// config/datify.php
'custom' => 'd/m/Y h:i A',
'defaults' => [
    'created_at' => 'custom',
    'updated_at' => 'custom',
],

// Later
$user->created_at; // "28/12/2024 01:37 PM"