🚨Laravel Tip: Avoid Race Conditions in Jobs
❌Bad:
$model->items()->create([...]);
$item = $model->items()->first();
✅Good:
$item = $model->items()->create([...]);
Why? Even in isolated jobs, first() can return null because:
- New DB query
- Cache inconsistency
- Commit delays
Always store the create() result directly!
Back