public function register(UserService $user) { $credentials = Request::only('email', 'password', 'password_confirmation', 'register_company'); try { $validation = $user->validateCreateUser($credentials); if (!$validation->fails()) { $credentials['password'] = Hash::make($credentials['password']); $new_user = new User(); $new_user->email = $credentials['email']; // $new_user->username = $credentials['username']; $new_user->password = $credentials['password']; if ($new_user->save()) { if (isset($credentials['register_company']) && $credentials['register_company'] == 1) { $company = new Company(); $company->user_id = $new_user->id; $company->save(); } else { $user_step = new UserStep(); $user_step->user_id = $new_user->id; $user_step->save(); } $token = JWTAuth::fromUser($new_user); $data = ['token' => $token, 'username' => $new_user->username, 'first_name' => $new_user->first_name, 'last_name' => $new_user->last_name]; return $this->json_response->success($data); } else { return $this->json_response->error(['error' => []]); } } else { return $this->json_response->error(['validation_message' => $validation->messages()]); } } catch (Exception $e) { return $this->json_response->error(['error' => $e->getMessage()]); } }
public function createCompany($user_id, $company_data) { try { $date_founded = $company_data['founded_year'] . '-' . $company_data['founded_month'] . '-' . $company_data['founded_date']; $company = new Company(); $company->user_id = $user_id; $company->name = $company_data['name']; if ($company_data['name'] === '' || empty($company_data['name'])) { $company->slug = $this->setSlug($company_data['name']); } $company->tax_vat_number = $company_data['tax_vat_number']; $company->employee_count = $company_data['employee_count']; $company->description = $company_data['description']; $company->street_name = $company_data['street_name']; /*$company->street_number = $company_data['street_number']; $company->building_name = $company_data['building_name']; $company->building_floor = $company_data['building_floor']; $company->building_room = $company_data['building_room'];*/ $company->city_town = $company_data['city_town']; /*$company->province = $company_data['province']; $company->region_state = $company_data['region_state'];*/ $company->zip_code = $company_data['zip_code']; $company->country = $company_data['country']; $company->date_founded = date('Y-m-d', strtotime($date_founded)); $company->contact_first_name = $company_data['contact_first_name']; $company->contact_last_name = $company_data['contact_last_name']; $company->contact_title = $company_data['contact_title']; $company->contact_email = $company_data['contact_email']; $company->contact_phone = $company_data['contact_phone']; $company->status_message = $company_data['status_message']; $company->lat = $company_data['lat']; $company->lng = $company_data['lng']; if ($company->save()) { return $company->load('company_logo_detail', 'company_cover_detail', 'company_video_detail')->toArray(); } return []; } catch (Exception $e) { return Response::json(['error' => $e->getMessage()]); } }