Looking to hire Laravel developers? Try LaraJobs

laravel-seeder maintained by bionicmaster

Description
Versioned, environment-based Seeders in Laravel
Last update
2018/03/07 18:57 (dev-master)
License
Links
Downloads
17

Comments
comments powered by Disqus

LaravelSeeder

Seeding as it is currently done in Laravel is intended only for dev builds, but what if you're iteratively creating your database and want to constantly flush it and repopulate it during development?

What if you want to seed a production database with different data from what you use in development? What if you want to seed a table you've added to a database that is currently in production with new data?

LaravelSeeder takes the database migration features in Laravel and extends them to database seeders, making them "migratable". All of the functionality you have grown accustomed to with Laravel migrations have been mirrored and behave similarly for seeders.

Requirements

  • Laravel >= 5.4
  • PHP >= 7.1

Installation

  • Run composer require bionicmaster/laravel-seeder
  • Add Eighty8\LaravelSeeder\SeederServiceProvider::class to your providers array in app/config/app.php
  • Run php artisan vendor:publish to push config files to your config folder if you want to override the name of the seeds folder or the name of the table where seeds are stored

Features

  • Allows you to seed databases in different environments with different values.
  • Allows you to "version" seeds the same way that Laravel currently handles migrations. Running php artisan seed will only run seeds that haven't already been run.
  • Allows you to run multiple seeds of the same model/table
  • Prompts you if your database is in production

Usage

When you install LaravelSeeder, various artisan commands are made available to you which use the same methodology you're used to using with Migrations.

Local Development

A Dockerfile with PHP 7.1 and Composer installed is bundled with the project to facilitate local development.

To build the image:

docker build -t laravel-seeder .

To install Composer dependencies:

docker run -v "$PWD":/usr/local/src laravel-seeder composer install

To run PHPUnit tests:

docker run -v "$PWD":/usr/local/src laravel-seeder vendor/bin/phpunit