asvae / laravel-fixtures by asvae

19
7
2
Package Data
Maintainer Username: asvae
Maintainer Contact: ontrew@gmail.com (Yauheni Prakopchyk)
Package Create Date: 2017-01-25
Package Last Update: 2017-01-25
Language: PHP
License: MIT
Last Refreshed: 2024-04-25 15:06:46
Package Statistics
Total Downloads: 19
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 7
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Intention

When working with database, sometimes we need to modify schema, and sometimes data. Doing both things in laravel migrations is painful. This package gives simple means to keep two of them separately.

Installation

Install via composer:

composer require asvae/laravel-fixtures

To your App\Console\Kernel add command like this:

protected $commands = [
    // ...
    
    \Asvae\LaravelFixtures\Commands\FixtureRun::class,
];

Usage

For your fixtures be sure to extend\Asvae\LaravelFixtures\AbstractFixture class or at least implement Asvae\LaravelFixtures\FixtureContract. Abstract class has several utility methods to keep you going:

$this->runFixture($className); // Runs another fixture.
$this->runArray($className); // Run [nested] array of fixtures

To run fixture do php artisan fixture:run "\App\Fixtures\YourFixture". This will basically run run method in given class, while also resolving dependencies in case you defined any in constructor.

Config

No config file provided as the library is way too small. You can define default namespace in .env file though. This will be used when you pass class name without namespace

FIXTURES_NAMESPACE=App\MyFixtures

Examples

Take a look at several examples. For the case depicted, in production, to fully migrate data you will run

php artisan fixture:run "\Asvae\LaravelFixtures\Examples\FixtureSet"

In development, to refresh single table you will run solitary fixtures as these are much faster.

Hints

  • You can copy namespaced class name in PHPStorm by placing cursor onto class name and pressing Ctrl (⌘) + Shift + Alt + C
  • If you want to add some functionality, feel free to just copy package in your project. Several classes won't hurt.
  • Spread a word or leave a star if what I did was helpful for you.