PHP code example of touhidurabir / laravel-seed-extender

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

    

touhidurabir / laravel-seed-extender example snippets




namespace Database\Seeders;

use Touhidurabir\SeedExtender\BaseTableSeeder;

class UsersTableSeeder extends BaseTableSeeder {
    
    /**
     * Seeder table name 
     *
     * @var string
     */
    protected $table = "users";


    /**
     * The table attributes/columns that will be ignored during the seeding process
     *
     * @var array
     */
    protected $ignorables = [];


    /**
     * The table attributes/columns that will be used during the seeding process
     *
     * @var array
     */
    protected $useables = [];


    /**
     * Should merge and 
     * @return array
     */
    protected function seedableDataBuilder() {

        foreach ($this->data as $key => $value) {
            
            $this->data[$key] = array_merge($value, [

            ]);
        }

        return $this->data;
    }
}

protected $data = [
    ['[email protected]', '123456'],
    ['[email protected]', '123456'],
];

protected function seedableDataBuilder() {

    foreach ($this->data as $key => $value) {
        
        $this->data[$key] = array_merge($value, [
            // any repetitive merge data 
            // it will merge to every row data defined in the $data proeprties
        ]);
    }

    return $this->data;
}

use Touhidurabir\SeedExtender\Facades\SeedExtender;

SeedExtender::table('table_name') //table name
    ->useables([]) // useables columns as array
    ->ignorables([]) // ignorables columns as array
    ->ing via eloquent model
    ->withModelEvents() // specific if want to have model events fire when running the seeding process via eloquent model
    ->run(); // run the seeding process
bash
php artisan make:extend-seeder UsersTableSeeder --table=users
bash
php artisan make:extend-seeder UsersTableSeeder --table=users --ignorables=id,deleted_at
bash
php artisan make:extend-seeder UsersTableSeeder --table=users --useables=name,email,password
bash
php artisan make:extend-seeder UsersTableSeeder --table=users --model='App\\Models\\User' --with-events --useables=name,email,password --no-timestamp
bash
php artisan make:extend-seeder UsersTableSeeder --table=users --replace
bash
php artisan make:extend-seeder UsersTableSeeder --table=users --useables=email,password --strict