示例#1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $user = $request->input('user', '');
     if (empty($id) || $user === '') {
         return new Response("Mandatory parameter(s) are missing.", 405);
     }
     try {
         $desk = Desk::findOrFail($id);
         $desk->users_id = $user;
         $desk->save();
     } catch (\Exception $e) {
         return new Response("There was an error while processing the update request: " . $e->getMessage(), 500);
     }
 }
示例#2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $from = $request->input('from', '');
     $to = $request->input('to', '');
     if (empty($id) || $from === '' || $to === '') {
         return new Response("Mandatory parameter(s) are missing.", 405);
     }
     try {
         if ($id > 0) {
             $user = User::findOrFail($id);
             $old_desk = $user->desk;
         } else {
             if ($id < 0) {
                 // Busy Flag
                 $old_desk = Desk::find($from);
             } else {
                 return new Response("Invalid user id.", 405);
             }
         }
         #print_r( $old_desk->toArray() );
         if ($old_desk != null && $from != $old_desk->id) {
             return new Response("Out of sync, user was moved someplace else already.", 409);
         }
         if ($to != 0) {
             $new_desk = Desk::findOrFail($to);
             if (!$this->checkEmptyDesk($new_desk)) {
                 return new Response("Out of sync, target desk is not empty.", 409);
             }
         } else {
             $id = 0;
         }
         $ret = [];
         if ($old_desk != null) {
             $old_desk->users_id = 0;
             $old_desk->save();
             $ret['old'] = $old_desk->toArray();
         }
         if (isset($new_desk)) {
             $new_desk->users_id = intval($id);
             $new_desk->save();
             $ret['new'] = $new_desk->toArray();
         }
         return response()->json($ret);
     } catch (\Exception $e) {
         return new Response("There was an error while processing the update request: " . $e->getMessage(), 500);
     }
 }