public function attendance($centre) { try { $centre = Crypt::decrypt($centre); $centre = Centre::find($centre); } catch (Exception $e) { return View::make('layouts.error'); } Excel::create($centre->name, function ($excel) use($centre) { $excel->setTitle('Attendance Sheet'); $excel->setCreator('Technothlon')->setCompany('Technothlon'); $excel->setDescription('Attendance Sheet for ' . $centre->name); $excel->sheet('Offline', function ($sheet) use($centre) { $sheet->appendRow(array('Name 1', 'Name 2', 'School', 'Roll')); $users = array(); foreach (User::where('centre_id', $centre->id)->wherePaid(1)->orderBy('school_id')->get() as $user) { $users[] = array($user->name1, $user->name2, $user->school->name, $user->roll); } $sheet->rows($users); }); $excel->sheet('Online', function ($sheet) use($centre) { $sheet->appendRow(array('Name 1', 'Name 2', 'School', 'Roll')); $users = array(); foreach (User::where('centre_id', $centre->id)->wherePaid(0)->orderBy('school_id')->get() as $user) { $users[] = array($user->name1, $user->name2, $user->school->name, $user->roll); } $sheet->rows($users); }); })->export('xlsx'); }