PHP code example of oi-lab / oi-laravel-seeds

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

    

oi-lab / oi-laravel-seeds example snippets




namespace Database\Seeders;

use App\Models\Group;
use Illuminate\Database\Seeder;
use OiLab\OiLaravelSeeds\Traits\ExportableSeeder;

class GroupSeeder extends Seeder
{
    use ExportableSeeder;

    protected string $jsonFilename = 'groups.json';
    protected string $modelClass = Group::class;
    protected array $dependencies = [];
    protected string $uniqueBy = 'name';
    protected array $exportRelations = [];

    public function run(): void
    {
        $this->importData();
    }
}

protected array $dependencies = [
    UserSeeder::class,
    RoleSeeder::class,
];

protected array $exportRelations = ['roles', 'permissions'];

protected function getExportableAttributes(mixed $model): array
{
    $attributes = $model->toArray();

    // Remove sensitive data
    unset($attributes['password'], $attributes['remember_token']);

    return $attributes;
}

protected array $jsonFilename = ['users.json', 'profiles.json'];
protected array $modelClass = [User::class, Profile::class];

protected array $uniqueBy = ['email', 'tenant_id'];

'storage_path' => env('OI_SEEDS_STORAGE_PATH', 'app/private/seeders'),
bash
php artisan vendor:publish --tag=oi-laravel-seeds-config
bash
php artisan vendor:publish --tag=oi-laravel-seeds-stubs
bash
php artisan make:exportable-seeder GroupSeeder --model=Group --unique-by=name
bash
php artisan seed:export --with-relations
bash
php artisan seed:export
bash
php artisan seed:export --seeder=GroupSeeder
bash
php artisan oi:skills