diff --git a/src/Illuminate/Foundation/Bus/Dispatchable.php b/src/Illuminate/Foundation/Bus/Dispatchable.php index 46b500559ff7..1fef9872f833 100644 --- a/src/Illuminate/Foundation/Bus/Dispatchable.php +++ b/src/Illuminate/Foundation/Bus/Dispatchable.php @@ -16,7 +16,7 @@ trait Dispatchable */ public static function dispatch(...$arguments) { - return new PendingDispatch(new static(...$arguments)); + return static::newPendingDispatch(new static(...$arguments)); } /** @@ -32,12 +32,12 @@ public static function dispatchIf($boolean, ...$arguments) $dispatchable = new static(...$arguments); return value($boolean, $dispatchable) - ? new PendingDispatch($dispatchable) + ? static::newPendingDispatch($dispatchable) : new Fluent; } return value($boolean) - ? new PendingDispatch(new static(...$arguments)) + ? static::newPendingDispatch(new static(...$arguments)) : new Fluent; } @@ -54,12 +54,12 @@ public static function dispatchUnless($boolean, ...$arguments) $dispatchable = new static(...$arguments); return ! value($boolean, $dispatchable) - ? new PendingDispatch($dispatchable) + ? static::newPendingDispatch($dispatchable) : new Fluent; } return ! value($boolean) - ? new PendingDispatch(new static(...$arguments)) + ? static::newPendingDispatch(new static(...$arguments)) : new Fluent; } @@ -97,4 +97,15 @@ public static function withChain($chain) { return new PendingChain(static::class, $chain); } + + /** + * Create a new pending job dispatch instance. + * + * @param mixed $job + * @return \Illuminate\Foundation\Bus\PendingDispatch + */ + protected static function newPendingDispatch($job) + { + return new PendingDispatch($job); + } }