2017 © Pedro Peláez
 

library l5-fixtures

A fixtures package for Laravel 5

image

mayconbordin/l5-fixtures

A fixtures package for Laravel 5

  • Thursday, January 18, 2018
  • by mayconbordin
  • Repository
  • 1 Watchers
  • 3 Stars
  • 26,563 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 1 Open issues
  • 2 Versions
  • 12 % Grown

The README.md

l5-fixtures

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Fixtures package for Laravel 5 with support for JSON, CSV, YAML and PHP files., (*2)

If you are seeding your database with fake data that can be easily generated, consider using the Model Factories., (*3)

But if you need to load data that can't be generated then this is your best choice., (*4)

Installation

In order to install Laravel 5 Fixtures, just add, (*5)

"mayconbordin/l5-fixtures": "dev-master"

to your composer.json. Then run composer install or composer update., (*6)

Then in your config/app.php add, (*7)

'Mayconbordin\L5Fixtures\FixturesServiceProvider'

in the providers array and, (*8)

'Fixtures' => 'Mayconbordin\L5Fixtures\FixturesFacade'

to the aliases array., (*9)

If you are using Laravel 5.5, package will be automatically discovered, no need to edit config/app.php, (*10)

Configuration

To publish the configuration for this package execute php artisan vendor:publish and a fixtures.php file will be created in your app/config directory., (*11)

Usage

By default the fixtures directory is /fixtures, inside it you should place the data files that will fill the database. The name of the file should be exactly the same as the name of the database table (e.g.: 'table_one.json'). Take a look at the two examples in the /tests_data directory., (*12)

To apply all fixtures to the database run, (*13)

Fixtures::up();

If you only want to apply some fixtures, you can pass an array with the name of the fixtures you want to apply, (*14)

Fixtures::up('table_one', 'table_two');

And to destroy the records in the database run, (*15)

Fixtures::down();

The down method can also receive an array with the name of fixtures that will be destroyed. Currently all records in the database tables are destroyed., (*16)

If you haven't published the configuration file or you want to load fixtures from another location, you only need to execute the following code before applying the fixtures:, (*17)

Fixtures::setUp('/path/to/fixtures');

Data Format

The fixtures files are parsed in order to create an array of records that are themselves associative arrays. The resulting array is then inserted in the database using the insert method of the query builder., (*18)

Relations are not handled by the library, but you can make reference to other records by their IDs, even if they haven't been inserted yet because the library disables the foreign key checks before inserting the fixtures into the database., (*19)

JSON

[
  {
    "name": "Owen Sound",
    "region": "ON",
    "country": "Sierra Leone"
  }
]

CSV

The delimiter is detected automatically., (*20)

name;region;country
Owen Sound;ON;Sierra Leone

YAML

- name: Owen Sound
  region: ON
  country: Sierra Leone

PHP

<?php

return [
    [
        'name' => 'Owen Sound',
        'region' => 'ON',
        'country' => 'Sierra Leone'
    ]
];

The Versions

18/01 2018

dev-master

9999999-dev https://github.com/mayconbordin/l5-fixtures

A fixtures package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maycon Viana Bordin

laravel csv json fixtures yaml laravel 5

07/10 2016

v1.0

1.0.0.0 https://github.com/mayconbordin/l5-fixtures

A fixtures package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maycon Viana Bordin

laravel csv json fixtures yaml laravel 5