Download the PHP package mayconbordin/l5-fixtures without Composer
On this page you can find all versions of the php package mayconbordin/l5-fixtures. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mayconbordin/l5-fixtures
More information about mayconbordin/l5-fixtures
Files in mayconbordin/l5-fixtures
Package l5-fixtures
Short Description A fixtures package for Laravel 5
License MIT
Homepage https://github.com/mayconbordin/l5-fixtures
Informations about the package l5-fixtures
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.
But if you need to load data that can't be generated then this is your best choice.
Installation
In order to install Laravel 5 Fixtures, just add
to your composer.json. Then run composer install
or composer update
.
Then in your config/app.php
add
in the providers
array and
to the aliases
array.
If you are using Laravel 5.5, package will be automatically discovered, no need to edit config/app.php
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
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.
To apply all fixtures to the database run
If you only want to apply some fixtures, you can pass an array with the name of the fixtures you want to apply
And to destroy the records in the database run
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:
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.
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
CSV
The delimiter is detected automatically.
YAML
PHP
All versions of l5-fixtures with dependencies
illuminate/support Version 5.x
illuminate/database Version 5.x
illuminate/console Version 5.x
league/csv Version ~8.0.0
symfony/yaml Version ~2.8.2
league/flysystem Version ~1.0.16