Published in Laravel

Laravel Application Helper Function: dispatch

By John Koster

dispatch($command)

The dispatch helper function can be used to push a new job onto the job queue (or dispatch the job). The function resolves the configured Illuminate\Contracts\Bus\Dispatcher implementation from the Service Container and then calls the dispatch method in the Dispatcher instance.

Assuming a variable $job exists that contains a valid queueable Job the following examples are all equivalent:

1<?php
2
3use Illuminate\Contracts\Bus\Dispatcher;
4use Illuminate\Support\Facades\Bus;
5
6dispatch($job);
7app(Dispatcher::class)->dispatch($job);
8Bus::dispatch($job);