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()]); } }