Skip to content

[READ-ONLY]The factory for Hyperf model.

License

Notifications You must be signed in to change notification settings

friendsofhyperf/model-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

model-factory

Latest Stable Version Total Downloads License

Installation

Install the package with Composer:

composer require friendsofhyperf/model-factory --dev

Also, publish the vendor config files to your application (necessary for the dependencies):

php bin/hyperf.php vendor:publish friendsofhyperf/model-factory

Example usage

/factories/user_factory.php

<?php


declare(strict_types=1);
/**
 * This file is part of friendsofhyperf/components.
 *
 * @link     https://github.com/friendsofhyperf/components
 * @document https://github.com/friendsofhyperf/components/blob/3.0/README.md
 * @contact  [email protected]
 */
use App\Model\User;


$factory->define(User::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->unique()->email,
    ];
});

/seeders/user_seeder.php

<?php

declare(strict_types=1);

use Hyperf\Database\Seeders\Seeder;
use App\Model\User;
use function FriendsOfHyperf\ModelFactory\factory;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run(): void
    {
        // Create 1 user with name 'Admin'
        factory(User::class)->create([
            'name' => 'Admin'
        ]);


        // Create 20 random users
        factory(User::class, 20)->create();
    }
}

Contact

License

MIT

About

[READ-ONLY]The factory for Hyperf model.

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages