chinleung / laravel-factory-builder
A package to use factories like an Eloquent builder.
Requires
- php: ^7.4
- illuminate/support: ^6.0|^7.0
Requires (Dev)
- orchestra/testbench: ^4.7
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-12-28 05:14:37 UTC
README
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.