chinleung/laravel-factory-builder

A package to use factories like an Eloquent builder.

v1.2.0 2020-04-27 18:15 UTC

This package is auto-updated.

Last update: 2024-03-28 03:36:26 UTC


README

Latest Version on Packagist Quality Score Total Downloads

A package to allow you to use your factories like an Eloquent builder inspired from Tighten.

Installation

You can install the package via composer:

composer require --dev chinleung/laravel-factory-builder

Configuration

By default, the builder will fetch the models from App\\ namespace if none has been provided in your builder.

php artisan vendor:publish --provider="ChinLeung\Factories\FactoriesServiceProvider" --tag="config"

Quick Usage

Basic

use Tests\Factories\UserFactory;

$user = app(UserFactory::class)->create();

Real-Time Facade

use Facades\Tests\Factories\UserFactory;

$user = UserFactory::create();

Methods

The builder comes with a few methods available for you to use.

create(int $count = null)

Create one or more instances of the model.

make(int $count = null)

Create one or more instances of the model without saving it in the database.

created(Model $model): Model

Hook to alter the model after it has been created. For instance, creating relationships related to the model.

setProperty(string $property, $value): self

Set a property for the creation of the model.

getProperties(): array

Retrieve the properties used for the model creation.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email hello@chinleung.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.