Laravel Factory:如何使一个字段有内容而另一个为空

Laravel Factory : How to make one field have content and the other one be null

我正在创建一个标签工厂,我希望它生成一个 project_tag_id 或一个 gobal_tag_id 但不能同时生成两个

return [
    'project_card_id' => ProjectCard::inRandomOrder()->first()->id,
    'user_id' => User::inRandomOrder()->first()->id,

    // to genreate project_tag_id or global_tag_id but not both
    'project_tag_id' => ProjectTag::inRandomOrder()->first()->id,
    'global_tag_id' => $this->faker->numberBetween(1,5),
  ];

如有任何帮助或见解,我们将不胜感激

Call a Random function if rand function return even insert project_tag_id else return global_tag_id 所以,

$number=rand(0,10);
if($number % 2 == 0){
  arr['project_tag_id'] => ProjectTag::inRandomOrder()->first()->id;
  arr['global_tag_id'] => null;
}else{
   arr['project_tag_id'] => null;
   arr['global_tag_id'] => $this->faker->numberBetween(1,5);
}