PHP code example of omaralalwi / laravel-time-craft

1. Go to this page and download the library: Download omaralalwi/laravel-time-craft 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/ */

    

omaralalwi / laravel-time-craft example snippets


return [
    // The default column used by all scopes when no field is given.
    'default_field' => 'created_at',

    // The format used by the HasReadableDates trait for the readable_* accessors.
    'readable_datetime_format' => 'F j, Y g:i A',
];

use Illuminate\Database\Eloquent\Model;
use Omaralalwi\LaravelTimeCraft\Traits\HasDateTimeScopes;

class Order extends Model
{
    use HasDateTimeScopes;
}

'default_field' => 'your_specific_field',

class Order extends Model
{
    use HasDateTimeScopes;

    protected $dateField = 'updated_at';
}

$lastWeekOrders = Order::lastWeek('updated_at')->get();

use Illuminate\Database\Eloquent\Model;
use Omaralalwi\LaravelTimeCraft\Traits\HasReadableDates;

class Order extends Model
{
    use HasReadableDates;
}

$order->readable_created_at;   // "April 30, 2023 3:49 PM"
$order->readable_updated_at;   // "April 30, 2023 3:49 PM"
$order->readable_deleted_at;   // "April 30, 2023 3:49 PM" (only when the model uses SoftDeletes)

$order->readableDate('shipped_at');   // "April 30, 2023 3:49 PM"

class Order extends Model
{
    use HasReadableDates;

    protected $appends = ['readable_created_at'];
}

// Per model:
class Order extends Model
{
    use HasReadableDates;

    protected $readableDateFormat = 'd/m/Y H:i';
}

// Globally, in config/laravel-time-craft.php:
'readable_datetime_format' => 'd M Y, g:i A',
bash
php artisan vendor:publish --tag=laravel-time-craft