In the first two lessons of the course, we examined examples of classes that can easily implement ShouldQueue
.
But generally speaking, and as I mentioned previously, there are three things for queues: jobs, queues, and workers. So, a job is a global thing that you can generate and put into a queue. Let's try to generate a simple job and put it into a queue.
Creating a Laravel Job
First, let's create a job using the Artisan command:
php artisan make:job SendRegisteredUserNotification
The main difference from classes we covered in the previous lessons is that jobs are generated by default with the Queueable
trait added and the ShouldQueue
interface implemented.
app/Jobs/SendRegisteredUserNotification.php:
use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Queue\Queueable; class SendRegisteredUserNotification implements ShouldQueue { use Queueable; public function __construct() { // } public function handle(): void { // }}
All of the job logic is applied in the handle()
method. Now, we can move the mail sending logic from...