JobWithModelPropertyDeclaresSerializesModelsRule
class JobWithModelPropertyDeclaresSerializesModelsRule implements Rule
A queued job (one implementing ShouldQueue) that holds an Eloquent model in a
property must use the SerializesModels trait.
A queued job is serialized to the queue store at dispatch and unserialized in
the worker. Without SerializesModels an Eloquent model property is serialized
whole: the full attribute set, loaded relations and casts go onto the wire,
bloating the payload, and the job runs against a frozen snapshot taken at
dispatch time, so any change made between dispatch and execution is silently
lost. SerializesModels instead stores just the class name and primary key
(plus the loaded relation names) and re-resolves the model fresh from the
database when the job runs, keeping the payload small and the data current. A
model deleted in the meantime then surfaces as a ModelNotFoundException
instead of the job operating on stale data.
Unlike upstream, which checks only public properties, every non-static
property counts, including a parent's private ones, because PHP serializes
them all. Properties typed against a model or an Eloquent collection (including
nullable unions) count, as SerializesModels converts both. An inherited
SerializesModels (used by the class, a parent, or another trait) satisfies
the rule, and a job with its own __serialize() decides its payload itself.
Traits
Methods
Get the node type the rule inspects.
Report a queued job with model properties that does not use SerializesModels.
Details
at line 62
string
getNodeType()
Get the node type the rule inspects.
at line 73
array
processNode(Node $node, Scope $scope)
Report a queued job with model properties that does not use SerializesModels.