예제 #1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit(Request $request, $id)
 {
     $circle = Circle::findOrFail($id);
     $grade = $circle->grade;
     if (isset($request->grade)) {
         $grade = $request->grade;
     }
     $pupils = Pupil::where('schoolenrolment', $circle->year - $grade + 1)->orderBy('surname')->get();
     $registered_pupils = $circle->pupils()->get();
     return view('circle.edit', ['circle' => $circle, 'grade' => $grade, 'pupils' => $pupils, 'registered_pupils' => $registered_pupils]);
 }
예제 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $circles = Circle::all();
     foreach ($circles as $circle) {
         $pupils = Pupil::where('schoolenrolment', $circle->year - $circle->grade + 1)->get();
         $count = rand(0, min(10, $pupils->count()));
         if ($count == 0) {
             continue;
         }
         if ($count == 1) {
             $pupil = $pupils->random();
             Registration::create(['circle_id' => $circle->id, 'pupil_id' => $pupil->id]);
         } else {
             $pupils = $pupils->random($count);
             foreach ($pupils as $pupil) {
                 Registration::create(['circle_id' => $circle->id, 'pupil_id' => $pupil->id]);
             }
         }
     }
 }
예제 #3
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $school = School::findOrFail($id);
     $registrations = Pupil::join('registration', 'pupil.id', '=', 'registration.pupil_id')->join('circle', 'registration.circle_id', '=', 'circle.id')->join('subject', 'circle.subject_id', '=', 'subject.id')->where('pupil.school_id', $school->id)->where('circle.year', SessionData::getYear())->get();
     return view('school.show', ['school' => $school, 'registrations' => $registrations]);
 }
예제 #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $pupil = Pupil::findOrFail($id);
     $pupil->delete();
     Session::flash('message', 'Die ausgewählte Schule wurde gelöscht');
     return redirect('pupil');
 }