Skip to main content

Regular Jobs: Creating, Dispatching and Adding Parameters

Premium
4 min read

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...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.