{"record":{"id":"6be3dcdd113facf5","repo":"laravel/framework","slug":"queueable-entity-type-not-found-for-id-id","errorCode":null,"errorMessage":"Queueable entity [{$type}] not found for ID [{$id}].","messagePattern":"Queueable entity \\[(.+?)\\] not found for ID \\[(.+?)\\]\\.","errorType":"exception","errorClass":"EntityNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/QueueEntityResolver.php","lineNumber":27,"sourceCode":"{\n    /**\n     * Resolve the entity for the given ID.\n     *\n     * @param  string  $type\n     * @param  mixed  $id\n     * @return mixed\n     *\n     * @throws \\Illuminate\\Contracts\\Queue\\EntityNotFoundException\n     */\n    public function resolve($type, $id)\n    {\n        $instance = (new $type)->find($id);\n\n        if ($instance) {\n            return $instance;\n        }\n\n        throw new EntityNotFoundException($type, $id);\n    }\n}\n","sourceCodeStart":9,"sourceCodeEnd":30,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Eloquent/QueueEntityResolver.php#L9-L30","documentation":"QueueEntityResolver.resolve() is used when a queued job serializes an Eloquent model by reference (ModelIdentifier) and Laravel re-fetches it on unserialization. If (new $type)->find($id) returns null - the row was deleted, the ID is wrong, or the model class changed - it throws EntityNotFoundException with the type and id.","triggerScenarios":"Dispatching a queued job with a model in its constructor, then deleting that model's row before the worker picks the job up; passing an unserialized/soft-deleted model id; model class rename leaving $type pointing at a stale class.","commonSituations":"Race between a delete and a queued worker; long-running queues holding stale references; deleting then re-running a queue:work; CI using an in-memory DB across processes; soft-deleted models without withTrashed on resolution.","solutions":["Catch \\Illuminate\\Contracts\\Queue\\EntityNotFoundException in the job's handle() and skip/retry/abort gracefully.","Pass the scalar ID (or a DTO) into the job instead of the model and re-fetch with findOrFail inside handle() so you control the missing-row behavior.","Use the SerializesModels trait (default) so the model is re-resolved; ensure the row still exists at runtime or handle its absence.","For soft-deleted models, fetch with withTrashed() in the job."],"exampleFix":"// before - dispatching the model\nProcessReport::dispatch($user);\n// later, user row deleted -> unserialize throws\n\n// after - pass ID, fetch in handle()\nclass ProcessReport implements ShouldQueue {\n    public function __construct(public int $userId) {}\n    public function handle() {\n        $user = User::find($this->userId);\n        throw_unless($user, new \\RuntimeException('User missing'));\n        // ...\n    }\n}\nProcessReport::dispatch($user->id);","handlingStrategy":"try-catch","validationCode":"// Prefer passing scalar IDs into jobs and re-fetch inside handle()\n// Validate existence at the boundary before dispatch:\nif (! User::whereKey($userId)->exists()) {\n    throw new \\RuntimeException(\"Cannot dispatch: user {$userId} missing\");\n}\nProcessJob::dispatch($userId);","typeGuard":"function entityExists(string $type, mixed $id): bool {\n    return (new $type)->whereKey($id)->exists();\n}","tryCatchPattern":"try {\n    // job body that resolves the model\n    $user = User::findOrFail($id);\n} catch (\\Illuminate\\Contracts\\Queue\\EntityNotFoundException $e) {\n    // row gone between dispatch and run - skip or requeue\n    $this->release(60); // or delete()\n}","preventionTips":["Pass scalar IDs into queued jobs; fetch inside handle() with findOrFail to control missing-row behaviour.","Catch EntityNotFoundException and decide skip/retry/fail rather than letting it bubble.","Avoid long delays between dispatch and processing when the underlying row can be deleted.","For soft-deleted models, fetch with withTrashed() in the job."],"tags":["queue","entity-resolver","jobs","serialization","model-identifier"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}