Open wirjo opened 5 years ago
Could you perhaps include the PHP & Laravel versions as well? Thanks!
Added. Thanks for maintaining this awesome plugin.
Do you have a full stack trace of the exception/error?
Sorry for the readability, but what I have for now is this screenshot here. When I get back to a computer in 24h, I can also provide the text output.
This is fine, thanks!
FYI - we are fixing this via abstracting the map()
logic into a separate class. Functionality now seems to be working correctly for our use cases.
namespace App;
use Illuminate\Database\Eloquent\Model as Model;
use Maatwebsite\LaravelNovaExcel\Actions\ExportToExcel;
use Illuminate\Contracts\Queue\ShouldQueue;
class SargonExport extends ExportToExcel implements ShouldQueue
{
/**
* @var string
*/
public $name = 'Export to Excel';
public function map($row): array
{
if ( $row instanceof Model ) {
// do nothing
} else {
// Convert to array first
$row = (array) $row;
}
return parent::map($row);
}
}
?>```
Problem
QueuedExport
of ahasMany
related model. In our case, we haveClients
hasManyDocuments
and we would like to export theDocuments
under theClient
view. The parameters that we used are:AppendQueryToSheet
job appears to be returning an error. The error appears to trace to$row
onmap($row)
being an object and not an array.https://github.com/Maatwebsite/Laravel-Nova-Excel/blob/806cafa2cf38de9a8f6c8cbc835445f406148b69/src/Actions/ExportToExcel.php#L227
Diagnosis
If we turn the $row object into an array (e.g.
$row = (array) $row;
), the queued export works also as normal. (I did this directly on the vendor file as a hack to test) https://github.com/Maatwebsite/Laravel-Nova-Excel/blob/806cafa2cf38de9a8f6c8cbc835445f406148b69/src/Actions/ExportToExcel.php#L227,If we change the action from
QueuedExport
toExportToExcel
, the export works so the issue appears to lie in the queueing mechanic.Note: Exports on the Document resource works perfectly fine. It’s only an issue when expiring Documents from the Client resource view.
Any assistance is appreciated.
Version Used Laravel-Nova-Excel: v1.10 Laravel: 5.7 PHP: 7.2