Use withoutRelations() when passing models to queue jobs to prevent large in-memory relationship graphs from serializing into queue storage.
When dispatching queue jobs that accept an Eloquent model instance, Laravel serializes the model. If the model had dozens of nested relationships eager-loaded in the controller, all those related models are serialized into the queue payload (Redis / Database), causing massive payload bloat.
Calling withoutRelations() strips loaded relations before dispatching.
Basic Usage
use App\Jobs\GenerateUserInvoiceJob;
public function checkout(Order $order)
{
// $order has heavy loaded relations (items, customer, history)
// Strips loaded relations so only the primary key is serialized
GenerateUserInvoiceJob::dispatch($order->withoutRelations());
}
In Job Class Constructors
Alternatively, clean relations in the constructor:
namespace App\Jobs;
use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\SerializesModels;
class ProcessOrderJob implements ShouldQueue
{
use Queueable, SerializesModels;
public Order $order;
public function __construct(Order $order)
{
$this->order = $order->withoutRelations();
}
}
Summary
- Reduces serialized queue payload sizes from megabytes to bytes.
- Prevents
Redis command size exceededor long text column limits injobstables. - Queue workers re-hydrate fresh relationships when needed.
Related Tips
View all tips →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.
Coordinate Complex Background Workflows with Bus::batch() and Bus::chain()
Use Bus::batch() to run parallel background jobs with completion callbacks, and Bus::chain() to execute sequential dependencies.