laravel-ide-helper
laravel-ide-helper copied to clipboard
Wrong methods on Collection when using maatwebsite/excel
Versions:
- ide-helper Version: 2.8.1 (also tried with dev-master)
- Laravel Version: 8.12.3
- PHP Version: 7.4.11 (windows)
Description:
I have installed package maatwebsite/excel
version 3.1.24. That package makes use of custom collections, and I'm finding that laravel-ide-helper
is using this package's DownloadCollection
and StoreCollection
as if it were Illuminate\Support\Collection
. This is what I get on _ide_helper.php
:
namespace Illuminate\Support {
/**
*
*
*/
class Arr {
}
/**
*
*
*/
class Str {
}
/**
*
*
*/
class Collection {
/**
*
*
* @param string $fileName
* @param string|null $writerType
* @param mixed $withHeadings
* @static
*/
public static function downloadExcel($fileName, $writerType = null, $withHeadings = false)
{
return \Illuminate\Support\Collection::downloadExcel($fileName, $writerType, $withHeadings);
}
/**
*
*
* @param string $filePath
* @param string|null $disk
* @param string|null $writerType
* @param mixed $withHeadings
* @static
*/
public static function storeExcel($filePath, $disk = null, $writerType = null, $withHeadings = false)
{
return \Illuminate\Support\Collection::storeExcel($filePath, $disk, $writerType, $withHeadings);
}
}
}
This is vendor\maatwebsite\excel\src\Mixins\DownloadCollection.php
:
<?php
namespace Maatwebsite\Excel\Mixins;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Sheet;
class DownloadCollection
{
/**
* @return callable
*/
public function downloadExcel()
{
return function (string $fileName, string $writerType = null, $withHeadings = false) {
$export = new class($this, $withHeadings) implements FromCollection, WithHeadings {
use Exportable;
/**
* @var bool
*/
private $withHeadings;
/**
* @var Collection
*/
private $collection;
/**
* @param Collection $collection
* @param bool $withHeading
*/
public function __construct(Collection $collection, bool $withHeading = false)
{
$this->collection = $collection->toBase();
$this->withHeadings = $withHeading;
}
/**
* @return Collection
*/
public function collection()
{
return $this->collection;
}
/**
* @return array
*/
public function headings(): array
{
if (!$this->withHeadings) {
return [];
}
$firstRow = $this->collection->first();
if ($firstRow instanceof Arrayable || \is_object($firstRow)) {
return array_keys(Sheet::mapArraybleRow($firstRow));
}
return $this->collection->collapse()->keys()->all();
}
};
return $export->download($fileName, $writerType);
};
}
}
File vendor\maatwebsite\excel\src\Mixins\StoreCollection.php
is pretty much the same, with only one method storeExcel()
.
Steps To Reproduce:
N/A
Hello,
I have the same problem. I hope that there will be a fix for it.
Any work around? Dives me up the wall..
They uhhh, are mixins that are injected into Laravels collection. This is actually accurate. The only issue is the return.