Re-load or pass model primary keys into queued jobs instead of relying on stale serialized relationship collections.
When Eloquent models are serialized for queue jobs, loaded relationships are serialized as well. If relationship records change before the job executes, workers operate on stale data. Pass IDs or call $model->refresh().
namespace App\Jobs;
use App\Models\Order;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendInvoiceJob implements ShouldQueue
{
public function __construct(public Order $order) {}
public function handle(): void
{
// Refresh model and reload relations to ensure fresh database state
$this->order->refresh()->load('items.product');
}
}
- Serialized job relations can become stale while sitting in queue backlogs
- Call $model->refresh() or reload relations inside handle() method
- Alternatively pass model primary keys (IDs) and query fresh inside job
Related Tips
View all tips →Refresh and Pessimistically Lock Models with refreshForUpdate() in Laravel 13.27
Laravel 13.27 adds refreshForUpdate(), reloading an existing model instance in-place with fresh database attributes while acquiring an exclusive FOR UPDATE row lock.
Scope Pivot Table Queries with Closures in wherePivot() in Laravel 13.26
Laravel 13.26 allows wherePivot() and orWherePivot() to accept closures, enabling direct reuse of local scopes defined on custom Pivot models.