我不确定这是我的错误还是误解......
阅读有关序列和关系的文档,我希望在$sequence->index
创建每个用户后,下面的代码会在报告工厂内重置,但是它对所有用户都存在。
预期效果应该是每个用户从现在开始有 90 天的报告,但是增量不断增长的意义最终最后一个用户报告在 900 天前结束(而不是 90 天)。
\App\Models\Recipient::factory(10)
->sequence(fn ($sequence) => [
'player_id' => $playerIds[$sequence->index]
])
->has(
\App\Models\Report::factory(90)
->sequence(fn ($sequence) => [
'created_at' => now()->subDay($sequence->index)
])
->state(fn (array $attributes, \App\Models\Recipient $recipient) => [
'player_id' => $recipient->player_id,
'user_id' => $recipient->user_id
])
)
->create([
'user_id' => 34
]);
我相信这是库本身的一个错误,很可能是由于一些静态值,或者我误解了文档?