dev-master
9999999-devGenerate a new seed file based on data from the existing database table.
BSD-2-Clause
The Requires
- php >=5.3.0
- illuminate/support 4.0.x
by Adam Engebretson
by Tihomir Opacic
Generate a new seed file based on data from the existing database table.
Seed generator (SeedGen) is a Laravel 4 package that provides a method to generate a new seed file based on data from the existing database table., (*1)
1) Edit your project's composer.json
file to require adamgoose/seed-gen
., (*2)
"require": { "laravel/framework": "4.0.*", "adamgoose/seed-gen": "dev-master" }
2) Update Composer from the CLI:, (*3)
composer update
3) Once this operation completes, add the service provider by opening a app/config/app.php
file, and adding a new item to the providers
array., (*4)
'Adamgoose\SeedGen\SeedGenServiceProvider'
To generate a seed file simply call: \SeedGen::generateSeed('users');
, (*5)
This will create a file inside a /app/database/seeds
, with the contents similar to following example:, (*6)
<?php // File: /app/database/seeds/UsersTableSeeder.php class UsersTableSeeder extends Seeder { /** * Auto generated seed file * * @return void */ public function run() { \DB::table('users')->delete(); \DB::table('users')->insert(array ( 0 => array ( 'id' => '1', 'email' => 'admin@admin.com', 'password' => '$2y$10$tUGCkQf/0NY3w1l9sobGsudt6UngnoVXx/lUoh9ElcSOD0ERRkK9C', 'permissions' => NULL, 'activated' => '1', 'activation_code' => NULL, 'activated_at' => NULL, 'last_login' => NULL, 'persist_code' => NULL, 'reset_password_code' => NULL, 'first_name' => NULL, 'last_name' => NULL, 'created_at' => '2013-06-11 07:47:40', 'updated_at' => '2013-06-11 07:47:40', ), 1 => array ( 'id' => '2', 'email' => 'user@user.com', 'password' => '$2y$10$ImNvsMzK/BOgNSYgpjs/3OjMKMHeA9BH/hjl43EiuBuLkZGPMuZ2W', 'permissions' => NULL, 'activated' => '1', 'activation_code' => NULL, 'activated_at' => NULL, 'last_login' => '2013-06-11 07:54:57', 'persist_code' => '$2y$10$C0la8WuyqC6AU2TpUwj0I.E3Mrva8A3tuVFWxXN5u7jswRKzsYYHK', 'reset_password_code' => NULL, 'first_name' => NULL, 'last_name' => NULL, 'created_at' => '2013-06-11 07:47:40', 'updated_at' => '2013-06-11 07:54:57', ), )); } }
This command will also update app/database/seeds/DatabaseSeeder.php
to include a call to this newly generated seed class., (*7)
To (re)seed the database go to the Terminal and run Laravel's db:seed command
(php artisan db:seed
)., (*8)
Generate a new seed file based on data from the existing database table.
BSD-2-Clause