Пример #1
0
 public function toArray(array $options = [])
 {
     $attributes = parent::toArray();
     $experience = $this->entity->experience()->first();
     if (!$experience) {
         $attributes['experience'] = null;
     } else {
         $experience = new Experience($experience);
         $attributes['experience'] = $experience->toArray();
     }
     $customer = $this->entity->customer()->first();
     if (!$customer) {
         $attributes['customer'] = null;
     } else {
         $customer = new Customer($customer);
         $attributes['customer'] = $customer->toArray();
     }
     return $attributes;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     // $business = app('business');
     try {
         $experience = $this->experience->findOrFail($id);
     } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         return response()->json([], 404);
     }
     $experience->fill(['name' => $request->input('experience.name'), 'description' => $request->input('experience.description'), 'price' => $request->input('experience.price'), 'status' => $request->input('experience.status')]);
     if (!$experience->validate()) {
         return response()->json(['errors' => $experience->getErrors()], 422);
     }
     $experience->save();
     $experience = new Experience($experience);
     return response()->json(['experience' => $experience->toArray()], 200);
 }