[Vuejs]-Laravel collection Call to a member function exports() on array

0πŸ‘

βœ…

Is the $jobs an id? If so, make it $jobId

public function export($jobId)
{  
    // assuming you have Job model which holds the jobs table
    $jobs = Job::where('id', $jobId)->get();

    return Excel::download(new JobsExport($jobs), 'jobs.xlsx');
}

and in your export class

class JobsExport implements WithStyles, FromCollection, WithMapping, WithHeadings
{
    use Exportable;
    
    private $jobs;

    public function __construct($jobs)
    {
        $this->jobs = $jobs;
    }

    public function collection()
    {
        // change this 
        //return $this->jobs->jobsExport();

        // to
        return $this->jobs;
    }

    public function map($jobsExport): array
    {
        // dd($jobsExport->templates->first()->template_name);
        return [
            $jobsExport->id,
            $jobsExport->templates->implode('template_name', ', '),
            $jobsExport->job_completed,
        ];
    }

    /**
    * @return \Illuminate\Support\Collection
    */ 
    public function headings():array
    {
        return[
            'Id',
            'Template',
            'Completed',
        ];
    } 
}

Leave a comment