Execution Modifiers
when() and unless()
These are the executable equivalents of Laravel's dispatchIf and dispatchUnless. They skip execution entirely if the condition is falsy:
SendWelcomeEmail::sync()->when($user->wantsEmails())->execute($user);
ProcessRefund::onQueue()->unless(fn() => $order->isAlreadyRefunded())->execute($order);Multiple conditions chain. The first false short-circuits:
NotifyUser::sync()
->when($user->isActive())
->when($user->hasVerifiedEmail())
->unless($user->isMuted())
->execute($user, $notification);When a condition fails, execute() returns null. The method is never called.
Closures are evaluated lazily. Use them when the condition involves an expensive check that should be skipped if an earlier condition already failed.
Only available in sync and queue modes (not prepare or test).
After-Response Execution
The executable equivalent of Laravel's dispatchAfterResponse. For sync executables that should run after the HTTP response is sent:
SendWelcomeEmail::sync()->afterResponse()->execute($user);This dispatches the work to Laravel's afterResponse callback. The response is sent to the client immediately; the executable runs after. execute() returns null since the result isn't available yet.
