public function setUsername(UsernameRequest $request) { $user = Auth::user(); if (isset($user->username)) { return redirect()->back()->withErrors('You already have a username.'); } $user->username = $request->input('username'); $user->save(); return redirect()->back()->withSuccess(config('constants.SAVED')); }
/** * updates username * @param $userId * @param UsernameRequest $usernameRequest * @param DatabaseManager $database * @return mixed */ public function updateUsername($userId, UsernameRequest $usernameRequest, DatabaseManager $database) { $input = $usernameRequest->all(); $user = $this->user->findOrFail($userId); $organization = $this->organization->findOrFail($this->orgId); $database->beginTransaction(); $organization->user_identifier = $input['organization_user_identifier']; $user->username = $input['username']; $user->save(); $organization->save(); $database->commit(); $response = $user->save() && $organization->save() ? ['type' => 'success', 'code' => ['updated', ['name' => 'Username']]] : ['type' => 'danger', 'code' => ['update_failed', ['name' => 'Username']]]; return redirect('user/profile')->withResponse($response); }