PHP code example of getupkid / laravel-eloquent-casts

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

    

getupkid / laravel-eloquent-casts example snippets


protected function casts(): array
{
    return [
        'is_active' => 'boolean',
        'settings' => 'json',
        'price' => 'decimal:2',
    ];
}



use Getupkid\LaravelEloquentCasts\Cast;

protected function casts(): array
{
    return [
        'is_active' => Cast::BOOLEAN,
        'settings' => Cast::JSON,
        'price' => Cast::decimal(2),
        'published_at' => Cast::datetime('Y-m-d H:i:s'),
    ];
}



use App\Casts\Money;
use App\Enums\UserStatus;
use Getupkid\LaravelEloquentCasts\Cast;
use Illuminate\Database\Eloquent\Casts\AsStringable;

protected function casts(): array
{
    return [
        'is_active' => Cast::BOOLEAN,
        'status' => UserStatus::class,
        'reference' => AsStringable::class,
        'asking_price' => Money::class,
    ];
}