Пример #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');
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Requests\PlanRequest $request, $id)
 {
     $plan = Auth::user()->plans()->findOrFail($id);
     $plan->update($request->all());
     return redirect()->action('PlanController@show', [$plan->id]);
 }
Пример #3
0
 /**
  * Guarda una sugerencia en el plan del usuario
  * @param PlanRequest $request
  * @return Response
  */
 public function store(PlanRequest $request)
 {
     $plan = new Plan($request->all());
     Auth::user()->plans()->save($plan);
     return redirect('plan');
 }