예제 #1
0
 /**
  * @param StudentSearch $request
  * @return mixed
  */
 private function createQuery(StudentSearch $request)
 {
     if (!$this->search->createQuery($request->all())) {
         return Student::orderBy('last_name', 'ASC')->paginate(10);
     }
     return $this->search->createQuery($request->all())->paginate(10);
 }
예제 #2
0
 public function createQuery($request)
 {
     $first_name = $request['first_name'];
     $last_name = $request['last_name'];
     $year = $request['year'];
     $section = $request['section'];
     $city = $request['city'];
     $age = $request['age'];
     $zip = $request['zip'];
     if ($zip || $first_name || $last_name || $year || $section || $city || array_key_exists($age, config('student.brackets'))) {
         $q = Student::orderBy('last_name', 'ASC');
         if ($first_name) {
             $q = $q->where('first_name', 'like', "%{$first_name}");
         }
         if ($last_name) {
             $q = $q->where('last_name', 'like', "%{$last_name}");
         }
         if ($zip) {
             $q = $q->where('zip', $zip);
         }
         if ($year) {
             $q = $q->where('year_level', $year);
         }
         if ($section) {
             $q = $q->where('section_id', $section);
         }
         if ($city) {
             $q = $q->where('city', $city);
         }
         if (array_key_exists($age, config('student.brackets'))) {
             $age = explode('-', $age);
             $q = $q->whereBetween('birthday', [Carbon::now()->subYears($age[1])->format('Y-m-d'), Carbon::now()->subYears($age[0])->format('Y-m-d')]);
         }
         return $q;
     }
     return false;
 }
 public function index()
 {
     return view('student.index', ['students' => Student::orderBy('name')->get()]);
 }
예제 #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $student = Student::find(Crypt::decrypt($id));
     if (count($student) == 0) {
         return response()->json(['success' => false, 'message' => 'Invalid id!']);
     }
     if (!$student->delete()) {
         return response()->json(['success' => false, 'message' => 'Failed to delete record!']);
     }
     $students = Student::orderBy('name')->get();
     return response()->json(['success' => true, 'message' => 'Delete record successful!', 'content' => view('partials.student-table', compact('students'))->render()]);
 }
예제 #5
0
 public function export(Request $request)
 {
     if ($request->get('dob') && $request->get('from') && $request->get('to')) {
         if ($request->get('from') < $request->get('to')) {
             return response()->json(['success' => false, 'message' => 'From date must be lower than TO date']);
         }
         $dt = Carbon::now();
         $dt2 = Carbon::now();
         $from = $dt->subYears($request->get('from'));
         $to = $dt2->subYears($request->get('to'));
         $students = Student::where('dob', '<=', $from)->where('dob', '>=', $to)->orderBy('fname')->get();
     } else {
         $students = Student::orderBy('fname')->get();
     }
     header('Set-Cookie: fileDownload=true; path=/');
     // This is required for the javascript triggering this will know if the transaction was successful.
     $data = $this->generateReportData($students, $request);
     Excel::create('reports-' . date('Ymd'), function ($excel) use($data) {
         $excel->sheet("Student Data", function ($sheet) use($data) {
             $sheet->fromArray($data);
         });
     })->download('xls');
 }