Dispatching jobs from the command line (CLI) in Laravel

Table of contents:

# Watch tutorial

# Code from video

<?php
namespace App\Jobs\Examples;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use MichaelLedin\LaravelJob\FromParameters;
class ExampleJob implements ShouldQueue, FromParameters
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(public string $videoName, public Carbon $releasedAt, public User $user)
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
dd($this->user);
// dd('Example job handle');
}
public static function fromParameters(...$parameters)
{
return new self($parameters[0], Carbon::parse($parameters[1]), User::find($parameters[2]));
}
}

# Useful links

mxl/laravel-job - Composer package for dispatching jobs from the Command Line Interface