public function details($id) { $store_audit = StoreAudit::findOrFail($id); $details = StoreAuditDetail::getDetails($store_audit->id); foreach ($details as $key => $value) { $img = explode(".", $value->answer); if (isset($img[1]) && strtolower($img[1]) == "jpg") { $link = url('auditimage/' . $id . '/' . $value->answer); $value->answer = $link; } } \Excel::create($store_audit->store_name . ' - ' . $store_audit->template_name, function ($excel) use($details) { $excel->sheet('Sheet1', function ($sheet) use($details) { $sheet->fromModel($details, null, 'A1', true); })->download('xls'); }); }