I have a fresh Laravel 10 app and I'm trying to test queues.
I created a job with php artisan make:job TestJob.
routes/web.php
Route::get('/test-job', function () {
\App\Jobs\TestJob::dispatch();
return 'Job dispatched';
});
.env
QUEUE_CONNECTION=database
TestJob.php
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class TestJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct() { /**/ }
public function handle()
{
\Log::info('TestJob executed successfully.');
}
}
When the job runs, it should write a log entry to storage/logs/laravel.log.
Ran migrations and started the worker:
php artisan queue:work
Problem:
When I visit /test-job, the job gets added to the jobs table, but it never executes.
Question: What configuration step am I missing to ensure my Laravel 10 jobs execute with the database queue?