A simple database seeder class with progress bar. Auto populates your database with fake records instantly. Less coding required, just filling your database field values. Currently supports four database system Mysql, Postgress, SQLite and SQL servers.
$ groovey seed:run Test
Install using composer. To learn more about composer, visit: https://getcomposer.org/
{
"require": {
"groovey/seeder": "~1.0"
}
}
Then run composer.phar
update.
On your project root folder. Create a file called groovey
.
#!/usr/bin/env php
<?php
set_time_limit(0);
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/database.php';
use Symfony\Component\Console\Application;
use Groovey\Seeder\DatabaseSeeder;
$seeder = new DatabaseSeeder();
$app = new Application;
$app->addCommands(
$seeder->getCommands()
);
$status = $app->run();
exit($status);
Change the default parameters of the database to your environment settings.
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'seeder',
'username' => 'root',
'password' => 'webdevel',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => ''
], 'default');
$capsule->bootEloquent();
$capsule->setAsGlobal();
return $capsule;
Great! Spam your database now.
Setup your seeder directory relative to your root folder ./database/seeds
.
$ groovey seed:init
Automatically creates a sample seeder class.
$ groovey seed:create Test
- Define your mysql test table
- Edit your
Test
class
Runs the seeder class
$ groovey seed:run Test
Here is a sample working seeder class.
<?php
class Test extends Seeder {
public $table = 'test';
public function run()
{
$faker = $this->faker;
$this->seed(function ($counter, $output) use ($faker) {
$faker->seed($counter);
return [
'name' => $faker->name,
'email' => $faker->email,
'created_at' => $faker->dateTimeThisMonth()
];
}, 100, $truncate = true);
return;
}
}
Give a star
to show your support and love for the project.
Fork Groovey Seeder
and send us some issues.