Ejemplo n.º 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 {
         $customer = $this->customer->findOrFail($id);
     } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         return response()->json([], 404);
     }
     $customer->fill(['first_name' => $request->input('customer.first_name'), 'last_name' => $request->input('customer.last_name'), 'email' => $request->input('customer.email'), 'phone' => $request->input('customer.phone')]);
     if (!$customer->validate()) {
         return response()->json(['errors' => $customer->getErrors()], 422);
     }
     $customer->save();
     $customer = new Customer($customer);
     return response()->json(['customer' => $customer->toArray()], 200);
 }