The script tried to call a method on an incomplete object

Viewed 1010

I have an excel file containing 8K products I'm using package laravel-excel when I upload the file just 1K of products being uploaded and then I got this error in jobs_faild table:

Error: The script tried to call a method on an incomplete object. 
Please ensure that the class definition "App\Imports\ImportProducts" 
of the object you are trying to operate on was loaded _before_ unserialize() 
gets called or provide an autoloader to load the class definition in /var/app/current/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php:107

Stack trace:
#0 /var/app/current/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php(107): method_exists(Object(__PHP_Incomplete_Class), 'middleware')
#1 /var/app/current/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(117): Maatwebsite\Excel\Jobs\ReadChunk->middleware()

My controller to upload the file:

public function updateOrCreateProduct(Request $request)
{
    $request->validate([
        'file' => 'required|file|mimes:xlsx,csv'
    ]);

    (new ImportProducts)->queue($request->file);

    return $this->apiRespone(success: "product updated");
}

ImportProducts file contains:

class ImportProducts implements
    ToCollection,
    WithChunkReading,
    ShouldQueue,
    WithEvents,
    SkipsEmptyRows,
    WithHeadingRow
{
    use Importable, RegistersEventListeners;

    public function collection(Collection $rows)
    {
        foreach ($rows as $row) {
            // my logic to store data to products table
        }
    }

    public function chunkSize(): int
    {
        return 100;
    }
}
0 Answers
Related