Download the PHP package brad-denver/paris-seeder without Composer
On this page you can find all versions of the php package brad-denver/paris-seeder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brad-denver/paris-seeder
More information about brad-denver/paris-seeder
Files in brad-denver/paris-seeder
Package paris-seeder
Short Description A simple database seeding class using Faker data and Paris models
License MIT
Homepage https://github.com/BradDenver/paris-seeder
Informations about the package paris-seeder
paris-seeder
A simple database seeding class using Faker data and Paris models
Example Syntax
The above example would create two roles and two users with each role.
Install and config
The easiest way to install paris-seeder and its dependencies (faker, idiorm, paris) is via Composer. This class is available through Packagist with the vendor and package identifier of brad-denver/paris-seeder
.
Paris-seeder does not require any configuration itself but the following steps show how to configure Idiorm and setup Paris models for its use.
An example Idiorm config
Examples
Lets assume we are going to seed a roles
table
id | title |
---|---|
1 | Boss |
2 | Worker |
and a users
table
id | name | role_id |
---|---|---|
1 | Sally Hard | 2 |
2 | Bob Lazy | 1 |
both with auto incrementing id fields.
Paris Models
fist we need to create classes for each table that extends the Paris Model class
The key thing here is that the models have a create_fake
method that accepts an Idiorm ORM
instance and Faker\Generator
instance and returns the record resulting from $orm->create
.
Seeder::seed
The seed method expects:
- a paris model instance (or the string/s to create one)
- the count of records to insert (defaults to 1)
- optional data to overide that provided by faker in
create_fake
- optional callback to be called for record that is inserted (it will be passed the new rocord and the faker instance)
- optional
Faker/Generator
instance to generate fake data (if omitted a new instance will be created) A basic example.
Overide faker data.
Suppling a callback.
Suppling a faker generator
Seeder::replicate
Sometimes there may be no need to use fake data for a certain table. Seeder::replicate
is helper method to copy all data from one table to another (assuming they have compatible schemas).
Seeder::delete_all
as its name suggests this method simply deletes all records for given models table. It is called as the first step of Seeder::replicate
and Seeder::delete_all_and_seed
Seeder::delete_all_and_seed
a helper method for the common use case of deleting and reseeding all data in a table. This method simply calls Seeder::delete_all
followed by Seeder:seed
for the given model. It accepts the same arguments as Seeder:seed
All versions of paris-seeder with dependencies
fzaninotto/faker Version 1.*
j4mie/idiorm Version 1.*
j4mie/paris Version 1.*