PHP code example of jn-jairo / laravel-eloquent-cast

1. Go to this page and download the library: Download jn-jairo/laravel-eloquent-cast 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/ */

    

jn-jairo / laravel-eloquent-cast example snippets




namespace App;

use Illuminate\Database\Eloquent\Model;
use JnJairo\Laravel\EloquentCast\HasAttributesCast;

class Foo extends Model
{
    use HasAttributesCast;

    protected $casts = [
        'uuid' => 'uuid',
        'is_admin' => 'boolean',
        'created_at' => 'datetime:Y-m-d H:i:s',
    ];
}

$foo = new Foo();
$foo->uuid = '72684d25-b173-468d-8d45-2a10b2cc3e9f';
$foo->is_admin = 1;
$foo->created_at = '2000-01-01 00:00:00';

print_r(gettype($foo->uuid));
// string

print_r(get_class($foo->uuid_));
// Ramsey\Uuid\Uuid

var_dump($foo->is_admin);
// bool(true)

print_r($foo->created_at);
Illuminate\Support\Carbon Object
(
    [date] => 2000-01-01 00:00:00.000000
    [timezone_type] => 3
    [timezone] => UTC
)
bash
php artisan vendor:publish --provider=JnJairo\\Laravel\\EloquentCast\\EloquentCastServiceProvider