PHP code example of bedoya / has-data

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

    

bedoya / has-data example snippets


use Bedoya\HasData\Traits\HasData;

class Raffle extends Model
{
    use HasData;

    protected $casts = [
        'data' => 'array',
    ];
}

$raffle->getData('grid.rows');        // returns 25
$raffle->getData('grid');             // returns [25, 40]
$raffle->setData('grid.cols', 40);    // sets the value and optionally saves
$raffle->hasData('grid.rows');        // returns true

return [
    'database' => [
        'column-name' => 'data',    // default JSON column name
        'nullable'    => true,
        'casts'       => 'array',
    ],
    'auto_save' => true,            // auto-save after setData()
];

class Client extends Model
{
    use HasData;

    protected string $dataColumn = 'metadata';
    protected $casts = [
        'metadata' => 'array',
    ];
}

class Client extends Model
{
    use HasData;

    public bool $hasDataAutoSave = false;
}