mmaged
5 months ago
560
3
Laravel

User Factory

Posted 5 months ago by mmaged

Why it is neccessry to put User factory inside function and return the id?!

$factory->define(Wallet::class, function (Faker $faker) {
    return [
        'name' => $faker->word,
        'user_id'=> function(){
            return Auth::id()?
                Auth::id() :
                factory(User::class)->create()->id();
        },
    ];
});

Please sign in or create an account to participate in this conversation.