PHP code example of soyhuce / laravel-factories-extended

1. Go to this page and download the library: Download soyhuce/laravel-factories-extended library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

soyhuce / laravel-factories-extended example snippets




use Soyhuce\LaravelFactoriesExtended\Factory;

class UserFactory extends Factory
{
    // Same like usual factories
}

$user = UserFactory::new()->create();
$posts = PostFactory::times(3)->of($user)->create();

$posts = PostFactory::times(3)->of($user, 'author')->create();

$comments = CommentFactory::times(3)->of($post, 'commentable')->create();

$comments = CommentFactory::times(3)->of($post, 'commentable')->of($user, 'user')->create();

$user = UserFactory::new()->create();
$post = PostFactory::new()->ofAuthor($user)->create();
$comments = CommentFactory::times(3)->ofCommentable($post)->ofUser($user)->create();