コード例 #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \App\Exercise  $exercise
  *
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $exercise)
 {
     if ($request->input('up')) {
         if ($exercise->status == 'new') {
             if ($exercise->reading != 0) {
                 $exercise->reading--;
             } else {
                 if ($exercise->memory != 0) {
                     $exercise->memory--;
                     if ($exercise->memory == 0) {
                         $exercise->setOldStatus(\Auth::user());
                     }
                 }
             }
             $exercise->save();
             $response = response('The exercise has been upped.');
         } else {
             $response = response()->json(['errors' => ['The exercise have the OLD status.']], 400);
         }
     } else {
         if ($request->input('new')) {
             $exercise->setNewStatus(\Auth::user());
             $exercise->save();
             $response = response('The NEW status has been defined.');
         } else {
             if ($request->input('old')) {
                 $exercise->setOldStatus(\Auth::user());
                 $exercise->save();
                 $response = response('The OLD status has been defined');
             } else {
                 $response = response()->json(['errors' => ['The key hasn\'t defined.']], 400);
             }
         }
     }
     return $response;
 }