Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel-excel not working to export xls file using blade with image

Excuse me, I want to use laravel-excel to export my report. This is the controller:

public function getExcelfile(){
        $users = UserService::findAllPublic();
        $total = UserService::count();
        $total_with_photo = UserService::countWithPhoto();
        Excel::create('excelfile', function($excel) use ($users, $total, $total_with_photo) {
            $excel->sheet('Excel', function($sheet) use ($users, $total, $total_with_photo) {
                $sheet->loadView('report.excel')->with("users", $users)->with("total", $total)->with("total_with_photo", $total_with_photo);
            });
        })->export('xls');
    }

This is the excel.blade.php located at report folder:

<html> <body> Total Registered User : {{$total}} Total Registered User With Photo : {{$total_with_photo}} <h1>Data User</h1> @if(!empty($users)) <table class="table table-striped table-bordered">
    <thead>
    <tr>
        <th>ID</th>
        <th>Photo</th>
        <th>Nama</th>
        <th>Struck</th>
        <th>Email</th>
        <th>Phone</th>
        <th>FB ID</th>
        <th>Timestamp</th>
        <th>Publish</th>
    </tr>
    </thead>
    @foreach ($users as $row)
    <tr>
        <td>{{$row->id}}</td>
        <td><img src="{{URL::asset('assets/images/upload/' . $row->photo)}}" width="200px"/></td>
        <td>{{$row->nama}}</td>
        <td>{{$row->struck}}</td>
        <td>{{$row->email}}</td>
        <td>{{$row->phone}}</td>
        <td>{{$row->fbid}}</td>
        <td>{{$row->timestamp}}</td>
        <td>{{$row->publish}}</td>
    </tr>
    @endforeach </table> @endif </body> </html>

Then this error appears:

PHPExcel_Exception

File http://myserver.com/projectname/public/assets/images/upload/DSCN1164.jpg not found!

That file is exist when I try to access it at browser.

like image 311
Khaneddy2013 Avatar asked Sep 30 '22 18:09

Khaneddy2013


1 Answers

Instead of:

<img src="{{URL::asset('assets/images/upload/' . $row->photo)}}"

you should use:

<img src="assets/images/upload/{{{ $row->photo }}}"

Of course assuming it's correct path

like image 197
Marcin Nabiałek Avatar answered Oct 03 '22 00:10

Marcin Nabiałek