Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shapeshifter's avatar

Maatwebsite\Excel export data with images

Hi Everyone! I was able to export the excel and to add the images but for some reason he dosent put the images aligned with the records. Some one can help me plz ?

   public function collection()
    {
        $data = Citation::where('user_id', auth()->id())->get();
        foreach($data as $citation)
        {
            $citations[] = array(
                'title'       => $citation->title,
                'source'      => $citation->source->name,
                'description' => $citation->description,
                'author'      => $citation->authors,
                'page_number' =>$citation->page_number,
                'publisher' =>  $citation->publisher,
                'year' => $citation->year,
                'source_url' => $citation->citation_source_url,
                'question' => $citation->question->name,
                'topic'=> $citation->topic->name,
                );

        }
        if(isset($citations))
        {
            $collection = collect($citations);
        }
        else
        {
            $citations = [];
            $collection = collect($citations);

        }

        return $collection;
    }

    public function drawings()
    {
        $data = Citation::where('user_id', auth()->id())->get();
        $drawings = [];
        foreach($data as $key=>$citation)
        {
            $drawing = new Drawing();
            $drawing->setPath(public_path('storage/'.$citation->citation_photo_path));
            $drawing->setHeight(50);
            $drawing->setWidth(120);
            $drawing->setCoordinates('K'.($key+1));
            $drawings [] = ($drawing);
        }
        return $drawings;
    }

    public function headings() :array
    {
        return ["Title","Source","Description","Author","Page Number","Publisher","Year","Citation Url","Question","Topic"];
    }
0 likes
2 replies
jhgjhgjh's avatar

public function collection() { $data = Citation::where('user_id', auth()->id())->get(); foreach($data as $citation) { $citations[] = array( 'title' => $citation->title, 'source' => $citation->source->name, 'description' => $citation->description, 'author' => $citation->authors, 'page_number' =>$citation->page_number, 'publisher' => $citation->publisher, 'year' => $citation->year, 'source_url' => $citation->citation_source_url, 'question' => $citation->question->name, 'topic'=> $citation->topic->name, );

    }
    if(isset($citations))
    {
        $collection = collect($citations);
    }
    else
    {
        $citations = [];
        $collection = collect($citations);

    }

    return $collection;
}

public function drawings()
{
    $data = Citation::where('user_id', auth()->id())->get();
    $drawings = [];
    foreach($data as $key=>$citation)
    {
        $drawing = new Drawing();
        $drawing->setPath(public_path('storage/'.$citation->citation_photo_path));
        $drawing->setHeight(50);
        $drawing->setWidth(120);
        $drawing->setCoordinates('K'.($key+1));
        $drawings [] = ($drawing);
    }
    return $drawings;
}

public function headings() :array
{
    return ["Title","Source","Description","Author","Page Number","Publisher","Year","Citation Url","Question","Topic"];
}
1 like

Please or to participate in this conversation.