A Laravel queued job gets the wrong data, or none at all
Illuminate\Database\Eloquent\ModelNotFoundExceptionShort answer
Laravel does not store a snapshot of a model you pass to a job. It stores the identifier and loads the row again when the worker runs. So a job can see newer data, fail because the row is gone, or run old code if the worker was never restarted. Check the failed-jobs list, restart workers, and dispatch after commit.
Fix it fast
1Find out which cause you have
List the failed jobs. A missing model shows up here with its exception, and an empty list points to the worker or a dropped dispatch instead.
php artisan queue:failed2Match what you see, then jump to its fix
- 1
You added or changed a constructor argument, but the job behaves as if the old signature is in useThe worker is still running the old job classFix - 2
ModelNotFoundException in queue:failed, or a job that sees no records created just before dispatchThe model is deleted, or not yet saved, when the job runsFix - 3
The job sees updated column values, or a relationship is missing the filter you set before dispatchThe data in the job is newer, or less complete, than you expectedFix - 4
The first dispatch ran, but later dispatches with other arguments never appear on the queueA unique job silently ignores the new dispatchFix
- 1
What does the error look like?
Illuminate\Database\Eloquent\ModelNotFoundExceptionThe job runs old code after a deployThe job never runs when dispatched with the same arguments again
Cause 1 of 4
The worker is still running the old job class
1Check
A queue worker is a long-lived process. It keeps the application it booted with in memory, so it does not notice changed files until it restarts.
ps aux | grep "queue:work"2Fix
Tell every worker to exit after its current job. Your process manager (Supervisor or similar) starts new ones that load the new code. Run this on every deploy.
php artisan queue:restart3Verify
Dispatch the job again and watch the worker pick it up with the new arguments.
php artisan queue:work --onceConfirmed by laravel.com
Cause 2 of 4
The model is deleted, or not yet saved, when the job runs
1Check
A model given to the constructor is stored as its identifier and fetched again when the job is handled. If dispatch happens inside a database transaction, a worker can pick the job up before the transaction commits, so the row does not exist yet. A row deleted while the job waited gives the same error.
php artisan queue:failed
grep -rn "DB::transaction" app/2Fix
Dispatch after the transaction commits. If deleted models are expected and the job is pointless without them, let Laravel drop the job quietly.
ProcessPodcast::dispatch($podcast)->afterCommit();
// inside the job class
public $deleteWhenMissingModels = true;3Verify
Run the code path that dispatches the job and confirm nothing new appears in the failed list.
php artisan queue:failedConfirmed by laravel.com
Cause 3 of 4
The data in the job is newer, or less complete, than you expected
1Check
Because the model is reloaded, values changed after dispatch are visible to the job. Relationship constraints applied before serialisation are not applied again. A collection or array of models also comes back without its loaded relationships.
grep -n "__construct" -A4 app/Jobs/ProcessPodcast.php2Fix
If the job needs a fixed value, pass that value itself (an ID, a string, an array of scalars) instead of the model. If it needs a relationship, load it inside handle(). Encode binary data with base64_encode before passing it.
public function __construct(
public int $podcastId,
public string $format,
) {}
public function handle(): void
{
$podcast = Podcast::with('episodes')->findOrFail($this->podcastId);
}3Verify
Process one job and compare the values it logs with the values you dispatched.
php artisan queue:work --onceConfirmed by laravel.com
Cause 4 of 4
A unique job silently ignores the new dispatch
1Check
A job that implements ShouldBeUnique is not dispatched while another instance of it is on the queue and unfinished. The lock is based on uniqueId(), so different arguments with the same id are dropped.
grep -rn "ShouldBeUnique\|uniqueId" app/Jobs/2Fix
Return an id that includes the argument that makes the job different, or remove the interface if the job should not be unique.
public function uniqueId(): string
{
return $this->podcastId.'-'.$this->format;
}3Verify
Dispatch twice with different arguments and run the worker until the queue is empty and confirm both jobs ran.
php artisan queue:work --stop-when-emptyConfirmed by laravel.com
How do I stop it coming back?
- Run php artisan queue:restart as the last step of every deploy.
- Pass plain values (IDs, strings, numbers) when the job needs a fixed input, and models only when current data is what you want.
- Use afterCommit() when you dispatch inside a transaction.
- Keep a look at queue:failed, or send failures to your error tracker, so a missing model is noticed on the first day.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix