Beispiel #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(PlanRequest $request, $id)
 {
     $input = $request->except('_method', '_token');
     $plan = Plan::findOrFail($id);
     $recent_number_year = $plan->number_year;
     $recent_number_semester = $plan->number_semester;
     if ($plan->update($input)) {
         for ($year = 1; $year <= $input['number_year']; $year++) {
             for ($sem = 1; $sem <= $input['number_semester']; $sem++) {
                 $semester = array("plan_id" => $plan->id, "year" => $year, "number" => $sem);
                 $existing = Semester::where($semester)->first();
                 if (empty($existing)) {
                     Semester::create($semester);
                 }
             }
         }
         if ($recent_number_year > $input['number_year'] || $recent_number_semester > $input['number_semester']) {
             DB::table('semesters')->where('plan_id', '=', $plan->id)->where(function ($query) use($input) {
                 $query->orWhere('year', '>', $input['number_year'])->orWhere('number', '>', $input['number_semester']);
             })->delete();
         }
         return redirect('/plans');
     }
 }
Beispiel #2
0
 public static function now()
 {
     $date = date('c');
     $semester = Semester::where('semester_startdate', '<', $date)->where('semester_enddate', '>', $date);
     return $semester;
 }
 public function change(Request $request)
 {
     $this->validate($request, ['id' => 'required|exists:semester']);
     Semester::where('aktif', 1)->update(['aktif' => 0]);
     $aktivasi = Semester::find($request->input('id'));
     $aktivasi->aktif = 1;
     $aktivasi->save();
     return redirect()->route('semester.ganti')->with('message', "Semester berhasil diaktifkan.");
 }