Exemplo n.º 1
0
 public function create(GoogleApiService $google, UserService $user)
 {
     try {
         $input = Request::all();
         $address = $input['street_name'] . ', ' . $input['city_town'] . ', ' . $input['zip_code'] . ', ' . $input['country'];
         $input['lat'] = 0;
         $input['lng'] = 0;
         $geocode = $google->geoCoding($address);
         if ($geocode['status'] == 'OK') {
             $input['lat'] = $geocode['lat'];
             $input['lng'] = $geocode['lng'];
             $birthday = $input['birth_year'] . '-' . $input['birth_month'] . '-' . $input['birth_date'];
             $input['birth_date'] = date('Y-m-d', strtotime($birthday));
             $input['username'] = $user->setUsername($input['first_name'] . ' ' . $input['last_name']);
             unset($input['password_confirmation']);
             unset($input['birth_year']);
             unset($input['birth_month']);
             $id = User::insertGetId($input);
             $user_step = new UserStep();
             $user_step->user_id = $new_user->id;
             $user_step->step1 = 1;
             $user_step->step2 = 1;
             $user_step->step3 = 1;
             $user_step->step4 = 1;
             $user_step->step5 = 1;
             $user_step->step6 = 1;
             $user_step->step7 = 1;
             $user_step->save();
             $response = User::where('id', '=', $id)->first()->toArray();
             if (!empty($response)) {
                 return $this->json_response->success($response);
             }
             return $this->json_response->error($response);
         } else {
             return $this->json_response->error(['validation_message' => $geocode['status']]);
         }
     } catch (Exception $e) {
         return $this->json_response->error(['error' => $e->getMessage()]);
     }
 }