jcloutz/forger

This package is abandoned and no longer maintained. No replacement package was suggested.

Intended to allow fast creation of populated model instances for database seeding.

1.0.2 2014-03-18 23:11 UTC

This package is not auto-updated.

Last update: 2020-05-15 16:52:09 UTC


README

Build Status

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();

License

WTFPL