Error when exporting to excell from laravel 5.5

1

I am using Maatwebsite to export an excell view, I tried to follow the steps that appear in its documentation, but I get the following error:

This is the code of my export:

<?php

namespace App\Exports;

use Carbon\Carbon;
use App\Intervention;
use App\Patient;
use App\Professional;
use App\User_intervention;

// use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;

class ExcellExport implements FromView
{
    /**
    * @return \Illuminate\Support\Collection
    */

    public function __construct($query)
    {
        $this->ini=$query->fini;
        $this->fin=$query->ffin;
    }

    public function fromview($f)
    {
        Carbon::setLocale('es');
        $fini = new Carbon($ini);
        $ffin = new Carbon($fin);
        $dfini = ($fini->day);
        $dffin = ($ffin->day);
        // $patients = Patient::where('attention', true)->get();
        $patients = Patient::whereIn('record', ['0004/01','0005/01','0046/02'])->select('record','name')->get();
        $profesionales = Professional::all();
        $datospatientprof=array();
        $datosfinales=array();
        $dia = $fini;
        foreach ($patients as $patient) {
            foreach ($profesionales as $profesional) {
                for ($i = $dfini; $i <= $dffin; $i++) {
                    $d1 = Intervention::where('date', $dia)->where('patient_record', $patient->record)
                        ->where('professional_id', $profesional->id)->whereIn('place_id', [1])->whereIn('type_id', [1, 3, 5, 13])
                        ->count('interventions.id');
                    $d2 = Intervention::where('date', $dia)->where('patient_record', $patient->record)
                        ->where('professional_id', $profesional->id)->whereIn('place_id', [2, 3])->whereIn('type_id', [1, 3, 5, 13])
                        ->count('interventions.id');
                    $d3 = Intervention::where('date', $dia)->where('patient_record', $patient->record)
                        ->where('professional_id', $profesional->id)->whereIn('place_id', [1])->whereIn('type_id', [2, 4, 6])
                        ->count('interventions.id');
                    $d4 = Intervention::where('date', $dia)->where('patient_record', $patient->record)
                        ->where('professional_id', $profesional->id)->whereIn('place_id', [2, 3])->whereIn('type_id', [2, 4, 6])
                        ->count('interventions.id');
                    $d5 = User_intervention::join('interventions', 'interventions.id', '=', 'user_interventions.interventions_id')
                    ->where('interventions.date', $dia)->where('user_interventions.patient_record', $patient->record)
                    ->where('interventions.professional_id', $profesional->id)->whereIn('interventions.place_id', [1])
                    ->whereIn('interventions.type_id', [9, 12])
                    ->count('user_interventions.id');
                    $d6 = User_intervention::join('interventions', 'interventions.id', '=', 'user_interventions.interventions_id')
                    ->where('interventions.date', $dia)->where('user_interventions.patient_record', $patient->record)
                    ->where('interventions.professional_id', $profesional->id)->whereIn('interventions.place_id', [2, 3])
                    ->whereIn('interventions.type_id', [9, 12])
                    ->count('user_interventions.id');
                    $d7 = User_intervention::join('interventions', 'interventions.id', '=', 'user_interventions.interventions_id')
                    ->where('interventions.date', $dia)->where('user_interventions.patient_record', $patient->record)
                    ->where('interventions.professional_id', $profesional->id)->whereIn('interventions.place_id', [1])
                    ->whereIn('interventions.type_id', [10])
                    ->count('user_interventions.id');
                    $d8 = User_intervention::join('interventions', 'interventions.id', '=', 'user_interventions.interventions_id')
                    ->where('interventions.date', $dia)->where('user_interventions.patient_record', $patient->record)
                    ->where('interventions.professional_id', $profesional->id)->whereIn('interventions.place_id', [2, 3])
                    ->whereIn('interventions.type_id', [10])
                    ->count('user_interventions.id');
                    $datospatientprof['nhist'] = $patient->record;
                    $datospatientprof['nombre'] = $patient->name;
                    $datospatientprof['profesional'] = $profesional->category;
                    $datospatientprof[$dia->format("d-m-Y").'-aiuc'] = $d1;
                    $datospatientprof[$dia->format("d-m-Y").'-aium'] = $d2;
                    $datospatientprof[$dia->format("d-m-Y").'-aifc'] = $d3;
                    $datospatientprof[$dia->format("d-m-Y").'-aifm'] = $d4;
                    $datospatientprof[$dia->format("d-m-Y").'-aguc'] = $d5;
                    $datospatientprof[$dia->format("d-m-Y").'-agum'] = $d6;
                    $datospatientprof[$dia->format("d-m-Y").'-agfc'] = $d7;
                    $datospatientprof[$dia->format("d-m-Y").'-agfm'] = $d8;
                    $dia->addDays(1);
                }
                $dia->subDays($dffin);
                $datosfinales[]=$datospatientprof;
            }
        }
        return view('indicators.excell', [
            'datosfinales' => $datosfinales,
            'dia' => $dia,
            'ffin' => $ffin,
            'dfini' => $dfini,
            'dffin' => $dffin
        ]);
    }
}

And here I call from the controller

public function excell(Request $request) {
    $f=array();
    $f['fini'] = new Carbon($request->input('date_start'));
    $f['ffin'] = new Carbon($request->input('date_end'));
    return Excel::download(new ExcellExport(request($f)), 'users.xlsx');
}
    
asked by Fernando Torres López 31.12.2018 в 10:35
source

0 answers