Download the PHP package zbm/m2m-seeding without Composer
On this page you can find all versions of the php package zbm/m2m-seeding. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zbm/m2m-seeding
More information about zbm/m2m-seeding
Files in zbm/m2m-seeding
Package m2m-seeding
Short Description seed fake data between many-to-many relation
License MIT
Informations about the package m2m-seeding
M2MSeeding
this package is useful for seeding fake data between two Models with Many-To-Many relationship by some function
Installation
Usage
Basic usage
- first thing call the static function make() with the first and second models you need with the name of relation from first model to second model
- then call run() to seeding the fake data
Factory the models
if you want to seed the models using factories you can call **withFactory() function**
the first parameter is the count of factories in the first model and the second parameter is for second one
Detect number of relations
you can use this functions to determine number of relations between the models
determine the minimum number of relations (the default value is 0).
determine the maximum number of relations (the default value is 3).
determine the minimum and maximum number of relations.
Seed the pivot
if the pivot have some data you can also seed it by using withPivot() function
this function accept callback function returned array of keys (the column name) and values (the value of column)
Example
First Model
Second Model
reactions table
- id
- user_id
- post_id
- reaction_type
Seeding
this lines will create 20 Post and 100 User and each Post has between 50 and 80 reactions and each reaction has type as integer between 1 and 6