SpartnerNL / Laravel-Nova-Excel

🚀 Supercharged Excel exports for Laravel Nova Resources
https://docs.laravel-excel.com/nova/1.0/
MIT License
379 stars 74 forks source link

Queued Export Failing on Export of hasMany related model #43

Open wirjo opened 5 years ago

wirjo commented 5 years ago

Problem

return (new QueuedExport)
                ->withDisk('s3')
                 ->withHeadings()
                 ->withChunkCount(200);

https://github.com/Maatwebsite/Laravel-Nova-Excel/blob/806cafa2cf38de9a8f6c8cbc835445f406148b69/src/Actions/ExportToExcel.php#L227

Diagnosis

Any assistance is appreciated.

Version Used Laravel-Nova-Excel: v1.10 Laravel: 5.7 PHP: 7.2

GlennM commented 5 years ago

Could you perhaps include the PHP & Laravel versions as well? Thanks!

wirjo commented 5 years ago

Added. Thanks for maintaining this awesome plugin.

patrickbrouwers commented 5 years ago

Do you have a full stack trace of the exception/error?

wirjo commented 5 years ago

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.

https://www.dropbox.com/s/27ligg5pyic009l/IMG_4596.PNG?dl=0

patrickbrouwers commented 5 years ago

This is fine, thanks!

wirjo commented 5 years ago

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);

    }

} 

?>```