Exemplo n.º 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]);
 }
Exemplo n.º 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]);
             }
         }
     }
 }