jcloutz / forger
Intended to allow fast creation of populated model instances for database seeding.
Installs: 175
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/jcloutz/forger
Requires
- php: >=5.4.0
- fzaninotto/faker: 1.4.*@dev
This package is not auto-updated.
Last update: 2020-05-15 16:52:09 UTC
README
This package is intended to allow for the fast creation of database objects in Laravel.
Installation
I the require key of your compser.json add the following.
"jcloutz/forger": "dev-master"
Run the compoer update command
$ composer update
Usage
Forger adds the ability to quickly retrieve a populated mockup of any model in your project. The Faker Package to generate mockup data based on an array of values.
<?php // namespace Models; use Jcloutz\Mocker\MockerTrait; class Widget extends Eloquent { use ForgerTrait; protected $table = 'widgets'; protected $fillable = []; public static $mockable = array( 'name' => 'A Fancy Widget', // Static data 'cost' => 'randomFloat|2|0|100', // Faker method with arguments 'price' => 'call|uppercase|word', // Call to user function with data from faker ); public function uppercase($string) { return strtoupper($string); } }
The ForgerTrait provides two static functions to models ::forge() and ::forgeCreate().
// Returns an instance of Widget without saving it to the database.
$widget = Widget::forge();
// Returns an instance of Widget and saves it to the database.
$widget = Widget::forgeCreate();