2017 © Pedro Peláez
 

library seeder

Export your database into Seeds

image

karakhanyans/seeder

Export your database into Seeds

  • Thursday, February 2, 2017
  • by karakhanyans
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Database Seeder

Seeder creates an artisan command that lets you quickly create seeds from your existing database., (*1)

Install

Via Composer, (*2)

composer require karakhanyans/seeder

In your app/config/app.php file, add the following to the providers array:, (*3)

 Karakhanyans\Seeder\SeederServiceProvider::class,

Usage

Once installed, you should see generate:seed as one of the artisan commands when you run:, (*4)

php artisan list

For example:, (*5)

php artisan generate:seed

This would create seed files in your database/seeds directory with a php files, which would contain the following stub:, (*6)

<?php

use Illuminate\Database\Seeder;

class UserSeed extends Seeder
{

    /**
    * Run the database seeds.
    *
    * @return void
    */

     protected $users;

     public function setUsers(){
        $this->users = //serialized data;
     }

     public function run(){
         $this->setUsers();
         foreach(unserialize($this->users) as $item){
             try{ 
                \App\User::create((array)$item);
            }catch (\Exception $e){
                \Illuminate\Support\Facades\Log::info('Duplicate entry for user: '.$item['id']);
             }
         }
     }

}

In your database/seeds/DatabaseSeeder.php file, add the following to the run() action to call all new seeds:, (*7)

$this->call(GlobalSeeder::class);

If your models in specific folder you should use {folder} argument to generate your Seeds from that folder., (*8)

 php artisan generate:seed Models

If you want to get all your models recursively you can use the following command with -r flag:, (*9)

php artisan generate:seed Models -r

Note

For Users table please remove $hidden array to make sure that Seeder will contain all database fields., (*10)

protected $hidden = ['password', 'remember_token'];

Change log

Please see CHANGELOG for more information what has changed recently., (*11)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*12)

Security

If you discover any security related issues, please email karakhanyansa@gmail.com., (*13)

Credits

License

The MIT License (MIT). Please see License File for more information., (*14)

The Versions

02/02 2017

dev-master

9999999-dev https://github.com/karakhanyans/seeder

Export your database into Seeds

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

database laravel eloquent model seeder laravel-seeder

02/02 2017

1.0.0

1.0.0.0 https://github.com/karakhanyans/seeder

Export your database into Seeds

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

database laravel model seeder laravel-seeder