Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $data = Items::find($id);
     if ($data) {
         if ($request->has('name')) {
             $data->name = $request->input('name');
         }
         if ($request->has('status') && ($status = States::find($request->input('status')))) {
             $data->status = $status->id;
         }
         if ($request->has('user_id') && ($person = Persons::find($request->input('user_id')))) {
             $data->user_id = $person->id;
         }
         if ($request->has('title')) {
             $data->title = $request->input('title');
         }
         if ($request->has('description')) {
             $data->description = $request->input('description');
         }
         if ($data->save()) {
             return $this->success($data);
         } else {
             return $this->error("failed to save");
         }
     } else {
         return $this->error("No person with this id");
     }
 }
Example #2
0
 public static function newId()
 {
     $newId = "";
     for ($i = 0; $i < 500; $i++) {
         $newId = "X";
         $characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         $charactersLength = strlen($characters);
         for ($s = 0; $s < 2; $s++) {
             $newId .= $characters[rand(0, $charactersLength - 1)];
         }
         if (!Persons::find($newId)) {
             return $newId;
         }
     }
 }
Example #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $data = Persons::find($id);
     if ($data) {
         if (Items::hasUser($data->id)->first()) {
             return $this->error("there is still an item allocated to his person");
         } else {
             $data->delete();
             return $this->success($data);
         }
     } else {
         return $this->error("No item with this id");
     }
 }