Skip to main content

Jobs into Groups: Batching and Chaining

Premium
7 min read

In this lesson, we'll explore how to organize and group multiple Laravel jobs using two powerful techniques: chaining and batching. These approaches help you execute related jobs in a controlled manner with better monitoring.


The Scenario

Imagine a user registers, and you want to perform several jobs afterward. For example, create the first task, then send a welcome message via the internal messaging system and notify the admin about the new users. What if you want to group all of those and monitor whether they succeed or not?

app/Http/Controllers/Auth/RegisteredUserController.php:

use App\Jobs\CreateFirstTask;
use App\Jobs\SendWelcomeMessage;
use App\Jobs\SendRegisteredUserNotification;
 
class RegisteredUserController extends Controller
{
// ...
 
public function store(Request $request): RedirectResponse
{
// ...
 
CreateFirstTask::dispatch($user->id);
SendWelcomeMessage::dispatch($user->id);
SendRegisteredUserNotification::dispatch($user);
 
Auth::login($user);
 
return redirect(route('dashboard', absolute: false));
}
}

Options For Grouping Laravel Jobs

In Laravel, there are two ways to group jobs: batching and chaining. What is the difference?

Imagine a scenario where you're firing...

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.