Answers for "laravel factory faker"

PHP
1

laravel factory relations data

factory(AppUser::class, 30)->create()->each(function($user) {

    $entity = factory(AppEntity::class)->make();

    $address = factory(AppAddress::class)->create([
        'entity_id' => $entity
    ]);

    $user->entities()->save($entity);
});
Posted by: Guest on December-19-2020
1

make model factory and controller laravel

php artisan make:model ModelName -a
// -a stands for all (Model, Controller, Factory and Migration)
// Note: The above command will work successfully in Laravel 5.5 or > versions
Posted by: Guest on February-06-2021
0

add factory data laravel

For Laravel version 7.* and less
factory(AppUser::class, 3)->make();

Use create method to persist them to the database:
factory(AppUser::class, 3)->create();
Posted by: Guest on November-28-2020

Browse Popular Code Answers by Language