public function singleReport($level, $id, $type) { if ($level == 'sm') { $singleReport = SMReport::findOrFail($id); } elseif ($level == 'am') { $singleReport = AMReport::findOrFail($id); } elseif ($level == 'mr') { $singleReport = Report::findOrFail($id); } \Excel::create('report-' . $level . '-' . $singleReport->emp->name . '-' . $singleReport->date, function ($excel) use($singleReport) { $excel->sheet('report', function ($sheet) use($singleReport) { $sheet->setAllBorders('thin'); $sheet->loadView('admin.export.single_report')->with('singleReport', $singleReport); }); })->export($type); }
public function singleAM($id) { $singleReport = AMReport::findOrFail($id); $singleReport['promotedProducts'] = AMReportPromotedProduct::select('product_id')->where('report_id', $singleReport->id)->get(); $singleReport['sampleProducts'] = AMReportSampleProduct::select('product_id')->where('report_id', $singleReport->id)->get(); $singleReport['gifts'] = AMReportGift::select('gift_id')->where('report_id', $singleReport->id)->get(); $singleReport['soldProducts'] = AMReportSoldProduct::select('product_id', 'quantity')->where('report_id', $singleReport->id)->get(); $dataView = ['singleReport' => $singleReport]; return view('sm.report.single', $dataView); }