PHP code example of kerigard / laravel-data

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

    

kerigard / laravel-data example snippets


use Illuminate\Database\Eloquent\Model;
use Kerigard\LaravelData\Contracts\MustFillData;
use Kerigard\LaravelData\Data;

class Role extends Model implements MustFillData
{
    public function data(): Data
    {
        return Data::make([
            ['id' => 1, 'name' => 'Admin'],
            ['id' => 2, 'name' => 'User'],
        ]);
    }
}

public function data(): Data
{
    return Data::make([
        // ...
    ], false);
}

class MyModel extends Model implements MustFillData
{
    public static function booted()
    {
        static::creating(function (MyModel $model) {
            $model->slug = Str::slug($model->name);
        });
    }

    public function data(): Data
    {
        return Data::make([
            // ...
        ])->withoutEvents(['eloquent.creating: '.MyModel::class]);
    }
}

use Kerigard\LaravelData\Data;
use Kerigard\LaravelData\DataManager;

public function boot()
{
    DataManager::model(VendorModel::class, fn () => Data::make([
        // ...
    ]));

    DataManager::table('role_user', fn () => Data::make([
        // ...
    ]));

    DataManager::table([
        'connection' => 'db2',
        'table' => 'permissions',
        'primaryKey' => 'id',
        'timestamps' => true,
    ], fn () => Data::make([
        // ...
    ]));
}
bash
php artisan db:data