Laravel - Queues - Ignoring Missing Models
When injecting an Eloquent model into a job, the model is automatically serialized before being placed on the queue and re-retrieved from the database when the job is processed. However, if the model has been deleted while the job was waiting to be processed by a worker, your job may fail with a ModelNotFoundException
.
For convenience, you may choose to automatically delete jobs with missing models by setting your job's deleteWhenMissingModels
property to true
. When this property is set to true
, Laravel will quietly discard the job without raising an exception:
/**
* Delete the job if its models no longer exist.
*
* @var bool
*/
public $deleteWhenMissingModels = true;