/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     try {
         $timetable = Timetable::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return redirect('/dashboard')->withErrors('Timetable not found.');
     }
     if ($timetable->user_id !== Auth::user()->id) {
         return redirect('/dashboard')->withErrors('Timetable not found.');
     }
     $this->validate($request, ['name' => 'required|min:1', 'hotData' => 'required']);
     $hot = new Hot();
     $hot->parseJson($request->input('hotData'));
     $hotValidator = $hot->validateHotFormatData();
     if ($hotValidator !== true) {
         return redirect()->back()->withInput()->withErrors($hotValidator);
     }
     $timetable->name = $request->input('name');
     $timetable->data = $hot->stringifyHotFormatArray();
     $timetable->has_period_numbers = $request->has('hasPeriodNumbers');
     $timetable->update();
     return redirect('/timetable/' . $timetable->id)->with(['success' => ['Your timetable has successfully been updated.']]);
 }