Back to articles
Why Passing Eloquent Models to Queued Jobs Can Be Problematic
How-ToDevOps

Why Passing Eloquent Models to Queued Jobs Can Be Problematic

via Dev.toAndré Luiz Lunelli

TL;DR Avoid dispatching jobs with full Eloquent models. SendOrderConfirmation :: dispatch ( $user ); Instead, pass only what the job actually needs. SendOrderConfirmation :: dispatch ( $user -> id ); Passing models can: Increase queue payload size Break jobs after deployments Expose sensitive data in logs or failed jobs Smaller payloads make your system more resilient, predictable, and safer. Read the Full Thing I still see this pattern frequently in PRs. And to be clear — I'm not trying to turn this into a big issue. It works. But it can also introduce surprisingly large problems for such a small decision. 1. Your queue payload may grow unexpectedly And most of the time, this isn't intentional. In larger systems, it's easy to forget that a model may already have relationships loaded. Sometimes those relationships were loaded earlier in the request lifecycle — possibly by code you didn't even write. $user -> load ( 'products' ); If that user has 50 products loaded, those relationships

Continue reading on Dev.to

Opens in a new tab

Read Full Article
3 views

Related Articles