SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.29k stars 1.92k forks source link

[BUG] Interface 'Maatwebsite\\Excel\\Concerns\\withHeadings' not found #2521

Closed pironti closed 4 years ago

pironti commented 4 years ago

Prerequisites

Versions

Description

I've created a job that run with database queue in laravel that makes a query then exports this query (array) as csv with headers.

Steps to Reproduce

App\Jobs\CalculateForecastPreview.php public function handle() { $data = new ForecastPreviewsExport($this->forecasts); ....

App\Exports\ForecastPreviewsExport.php `<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromArray; use Maatwebsite\Excel\Concerns\withHeadings;

class ForecastPreviewsExport implements FromArray, withHeadings { protected $forecasts;

public function __construct(array $forecasts)

{
    $this->forecasts = $forecasts;
}

public function array(): array
{
    return $this->forecasts;
}

public function headings(): array{
    return [
        "id",
        "filial",
        "production",
        "partnership_production",
        "user_name",
        "directorships_id",
        "created_at",
        "updated_at",
    ];
}

}`

Then run in Terminal php artisan queue:work

composer.json "maatwebsite/excel": "^3.1"

\config\app.php ` 'providers' => [ ... Maatwebsite\Excel\ExcelServiceProvider::class, ]

'aliases' => [ ... 'Excel' => Maatwebsite\Excel\Facades\Excel::class,

] `

I've already tried composer update, composer auto-dump, etc

Expected behavior: Run the job successfully

Actual behavior:

Exception Jan 23 07:43:19 silent-plateau php [2020-01-23 12:43:19] production.ERROR: Interface 'Maatwebsite\Excel\Concerns\withHeadings' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Interface 'Maatwebsite\\Excel\\Concerns\\withHeadings' not found at /home/forge/forecast.parceirodeconsorcio.com.br/app/Exports/ForecastPreviewsExport.php:8) Jan 23 07:43:19 silent-plateau php [stacktrace] Jan 23 07:43:19 silent-plateau php #0 /home/forge/forecast.parceirodeconsorcio.com.br/vendor/composer/ClassLoader.php(444): include() Jan 23 07:43:19 silent-plateau php #1 /home/forge/forecast.parceirodeconsorcio.com.br/vendor/composer/ClassLoader.php(322): Composer\\Autoload\\includeFile() Jan 23 07:43:19 silent-plateau php #2 [internal function]: Composer\\Autoload\\ClassLoader->loadClass() Jan 23 07:43:19 silent-plateau php #3 /home/forge/forecast.parceirodeconsorcio.com.br/app/Jobs/CalculateForecastPreviews.php(54): spl_autoload_call() Jan 23 07:43:19 silent-plateau php #4 [internal function]: App\\Jobs\\CalculateForecastPreviews->handle() Jan 23 07:43:19 silent-plateau php #5 /home/forge/forecast.parceirodeconsorcio.com.br/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array() Jan 23 07:43:19 silent-plateau php #6 /home/forge/forecast.parceirodeconsorcio.com.br/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}() Jan 23 07:43:19 silent-plateau php #7 /home/forge/forecast.parceirodeconsorcio.com.br/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\\Container\\Util::unwrapIfClosure() Jan 23 07:43:19 silent-plateau php #8 /home/forge/forecast.parceirodeconsorcio.com.br/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod()

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

patrickbrouwers commented 4 years ago

use Maatwebsite\Excel\Concerns\withHeadings;

It's case sensitive, note that small letter w, needs to be WithHeadings

pironti commented 4 years ago

Thanks man!!!!!!!!! I didn't see it. And for some reason works fine in my machine!

khanay1981 commented 3 years ago

i have this proble also can u help me please?