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]);
}
}