What is $content? I assume it should throw an exception when it is null not the other way around? You don't actually set anything, just throw an error?
@throws \LogicException when the content is not null
null may not be sufficient enough, if $content is just empty for example.
To check for an empty string, you can do !== "" as well.
Jul 28, 2020
17
Level 1
Maatwebsite/excel BinaryFileResponse error
Hi, I'm using PHP 7.3.13 and Laravel 6.4.1, Maatwebsite/excel 3.1.
This is my export:
<?php
namespace Edito\Exports;
use Edito\Models\Cms\Event;
use Maatwebsite\Excel\Concerns\FromCollection;
class ParticipantsExport implements FromCollection
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return Event::all();
}
}
And this is my controller:
public function getDump()
{
return \Excel::download(new ParticipantsExport(), 'dump.xls');
}
I get this error: "The content cannot be set on a BinaryFileResponse instance.", form this method in BinaryFileResponse class:
/**
* {@inheritdoc}
*
* @throws \LogicException when the content is not null
*/
public function setContent($content)
{
if (null !== $content) {
throw new \LogicException('The content cannot be set on
a BinaryFileResponse instance.');
}
return $this;
}
The reason is in method setContent(), variable $content instead of null is empty string like this: ''. When I manualy set content to null:
$content = null;
or even comment out whole method, my download works with no erros.
Someone has any idea what can be wrong?
Please or to participate in this conversation.