1

我有以下播种机。

User::factory(100)
    ->has(Loan::factory()->count(5))
    ->has(Transaction::factory()->count(5)
    ->has(TransactionDetail::factory()->count(1), 'transaction_detail'))
    ->create();

现在我想根据 User 类中的已验证属性调用另一个 Verification 类。因此已验证可能具有三个可能的值-“待定”、“未验证”、“已验证”。现在,当它经过验证或待处理时,我想创建一个 Verification 类。但是当它未经验证时,我不想调用那个类。像这样的东西...

User::factory(100)
    ->($user->verified !== 'unverfied') ? has(Verification::factory()) : null
    ->has(Loan::factory()->count(5))
    ->has(Transaction::factory()->count(5)
    ->has(TransactionDetail::factory()->count(1), 'transaction_detail'))
    ->create();

现在,我知道这种语法没有任何意义。但我只是想解释我的问题。如何根据 $user->verified 调用这个验证工厂?提前致谢。

4

0 回答 0