Use the $deleteWhenMissingModels property on queued jobs to silently discard jobs if their referenced database records were deleted before execution.
When an Eloquent model is passed to a queued job and a user deletes that record before the worker picks up the job, Laravel throws a ModelNotFoundException, causing the job to fail and populate the failed_jobs table.
Setting $deleteWhenMissingModels = true instructs the worker to delete the job silently.
Enabling on Job Classes
namespace App\Jobs;
use App\Models\Post;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class GeneratePostThumbnailJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
// Silently delete job if the Post model was deleted from database
public bool $deleteWhenMissingModels = true;
public function __construct(public Post $post) {}
public function handle(): void
{
// Process thumbnail
}
}
Summary
- Prevents false-alarm errors in
failed_jobsand error tracking tools (Sentry, Bugsnag). - Silently purges queued tasks when parent models are deleted.
- Standard property provided by the
SerializesModelstrait.
Related Tips
View all tips →Monitor Aggregate Queue Metrics with Total Size Helpers in Laravel 13.27
Laravel 13.27 adds totalPendingSize(), totalDelayedSize(), and totalReservedSize() to the Queue facade, making it easy to aggregate queue metrics for dashboards and health checks.
Debounce Queued Event Listeners with #[DebounceFor] in Laravel 13.26
Laravel 13.26 extends the #[DebounceFor] attribute to queued event listeners, collapsing bursts of repeated events into a single execution based on the latest resource state.