Search code examples
laravel-7laravel-queue

Laravel Queue : Class Illuminate\Bus\Dispatcher contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods


I was trying to add Queue to one of my existing Laravel projects. I have tried different tutorials related to queuing in Laravel such as this. I have created a fresh Laravel project and tried this and it was working fine. I have found that this question has already been asked before in Stackoverflow here, but I couldn't find any solution posted there. Any help is highly appreciated. Below are the codes :

EmployeesController.php

....
dispatch(new EmployeeListExportJob(['data'=>$data,'countries'=>$countries,'format'=>$request->format]));
....

EmployeeListExportJob.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;
use Excel;
use App\Exports\EmployeesExportExcel;

class EmployeeListExportJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


    protected $details;
    protected $data;
    protected $countries;
    protected $format;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($details)
    {
        $this->data = $details['data'];
        $this->countries = $details['countries'];
        $this->format = $details['format'];
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Excel::download(new EmployeesExportExcel($this->data, $this->countries), 'Employees.xlsx');
    }
}

I tried a custom dispatcher class, custom queue class and also I have tried adding the missing methods (findBatch,batch,dispatchSync) inside the EmployeeListExportJob class. But nothing worked.

I got the same error : Class Illuminate\Bus\Dispatcher contains 3 abstract methods and must therefore be declared abstract or implement the missing methods (Illuminate\Contracts\Bus\QueueingDispatcher::findBatch, Illuminate\Contracts\Bus\QueueingDispatcher::batch, Illuminate\Contracts\Bus\Dispatcher::dispatchSync)


Solution

  • This was automatically fixed after updating the Laravel version from 7 to Laravel 8.