user = $user; $user->role = UserRole::CUSTOMER; // チェック処理 $this->checkEmailForCreate(); $this->checkCustomerCode(); $user->save(); } public function createShopUser(Shop $shop, User $user) { $this->user = $user; $user->role = UserRole::SHOP; $user->shop_id = $shop->id; // チェック処理 $this->checkEmailForCreate(); $this->checkCustomerCode(); $user->save(); } private function checkEmailForCreate() { if (User::whereEmail($this->user) ->exists() ) { ParamException::throw(User::COL_NAME_EMAIL, trans('validation.unique')); } } private function checkCustomerCode() { $customer = MstCustomer::whereCustomerId($this->user->customer_code) ->first(); if ($customer === null) { ParamException::throw(User::COL_NAME_CUSTOMER_CODE, trans('validation.exists')); return; } $this->user->customer_id = $customer->id; } }