🔴 Laravel Intermediate

What are Jobs and Queues in Laravel?

Answer

Jobs represent units of work that can be queued for asynchronous background processing. Create: php artisan make:job SendWelcomeEmail. The handle() method contains the job logic. Implement ShouldQueue to queue it; without it, it runs synchronously. Dispatch: SendWelcomeEmail::dispatch($user). Dispatch with delay: ::dispatch()->delay(now()->addMinutes(5)). Specify queue: ::dispatch()->onQueue("emails"). Set maximum tries: public int $tries = 3. Set timeout: public int $timeout = 60. On failure (after all retries): public function failed(Throwable $e) method is called. Process a specific queue: php artisan queue:work --queue=emails,default. Use Laravel Horizon for a Redis-powered queue dashboard.