PHPackages                             mayconbordin/l5-fixtures - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. mayconbordin/l5-fixtures

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

mayconbordin/l5-fixtures
========================

A fixtures package for Laravel 5

v1.0(9y ago)4123.4k7[1 issues](https://github.com/mayconbordin/l5-fixtures/issues)MITPHPPHP &gt;=5.5.0

Since Oct 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/mayconbordin/l5-fixtures)[ Packagist](https://packagist.org/packages/mayconbordin/l5-fixtures)[ Docs](https://github.com/mayconbordin/l5-fixtures)[ RSS](/packages/mayconbordin-l5-fixtures/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

l5-fixtures
===========

[](#l5-fixtures)

[![Build Status](https://camo.githubusercontent.com/c889bef2467b9d46f611b6db2dc50a41422c5bfe7a681efddaeb5012523d2677/68747470733a2f2f7472617669732d63692e6f72672f6d6179636f6e626f7264696e2f6c352d66697874757265732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mayconbordin/l5-fixtures) [![Latest Stable Version](https://camo.githubusercontent.com/f003a61a4bfe54751fac356bc3b5b58fe295b61ab2efdc9fb9a9bad9380aa8dc/68747470733a2f2f706f7365722e707567782e6f72672f6d6179636f6e626f7264696e2f6c352d66697874757265732f762f737461626c65)](https://packagist.org/packages/mayconbordin/l5-fixtures) [![Total Downloads](https://camo.githubusercontent.com/3d92dc772f626bf8d0f556468da2499292024a38888c032fd1c9a6acc6c43532/68747470733a2f2f706f7365722e707567782e6f72672f6d6179636f6e626f7264696e2f6c352d66697874757265732f646f776e6c6f616473)](https://packagist.org/packages/mayconbordin/l5-fixtures) [![Latest Unstable Version](https://camo.githubusercontent.com/e11de630dab4fde0e43db670172352817b986794012827551408ee4ff65540e2/68747470733a2f2f706f7365722e707567782e6f72672f6d6179636f6e626f7264696e2f6c352d66697874757265732f762f756e737461626c65)](https://packagist.org/packages/mayconbordin/l5-fixtures) [![License](https://camo.githubusercontent.com/b6cef7b203f8197762e786e5a320e7d77d001880367575d3943e03608a890559/68747470733a2f2f706f7365722e707567782e6f72672f6d6179636f6e626f7264696e2f6c352d66697874757265732f6c6963656e7365)](https://packagist.org/packages/mayconbordin/l5-fixtures)

Fixtures package for Laravel 5 with support for JSON, CSV, YAML and PHP files.

If you are seeding your database with fake data that can be easily generated, consider using the [Model Factories](http://laravel.com/docs/5.1/seeding#using-model-factories).

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

Installation
------------

[](#installation)

In order to install Laravel 5 Fixtures, just add

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

to your composer.json. Then run `composer install` or `composer update`.

Then in your `config/app.php` add

```
'Mayconbordin\L5Fixtures\FixturesServiceProvider'
```

in the `providers` array and

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

to the `aliases` array.

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

Configuration
-------------

[](#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.

Usage
-----

[](#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`](https://github.com/mayconbordin/l5-fixtures/tree/master/tests/_data) directory.

To apply all fixtures to the database run

```
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

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

And to destroy the records in the database run

```
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.

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:

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

Data Format
-----------

[](#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](http://laravel.com/docs/5.1/queries#inserts) method of the query builder.

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.

#### JSON

[](#json)

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

#### CSV

[](#csv)

The delimiter is detected automatically.

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

#### YAML

[](#yaml)

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

#### PHP

[](#php)

```
