From fc8ca69729e858f3694a8e5ade4c065b636adaf0 Mon Sep 17 00:00:00 2001 From: "B.Fatih KOZ" Date: Mon, 30 Aug 2021 19:55:33 +0300 Subject: [PATCH] Fix Private Profile fields not being editable (#1289) * Update ProfileController.php * Update UserRepository.php * Update UserRepository.php Co-authored-by: Nabeel S --- app/Http/Controllers/Frontend/ProfileController.php | 2 +- app/Repositories/UserRepository.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Frontend/ProfileController.php b/app/Http/Controllers/Frontend/ProfileController.php index 5cde48be..c19e4b05 100644 --- a/app/Http/Controllers/Frontend/ProfileController.php +++ b/app/Http/Controllers/Frontend/ProfileController.php @@ -123,7 +123,7 @@ class ProfileController extends Controller $airlines = $this->airlineRepo->selectBoxList(); $airports = $this->airportRepo->selectBoxList(false, setting('pilots.home_hubs_only')); - $userFields = $this->userRepo->getUserFields($user, true); + $userFields = $this->userRepo->getUserFields($user); return view('profile.edit', [ 'user' => $user, diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 0d8debaf..e540d092 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -36,9 +36,14 @@ class UserRepository extends Repository * * @return \App\Models\UserField[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection */ - public function getUserFields(User $user, $only_public_fields = true): Collection + public function getUserFields(User $user, $only_public_fields = null): Collection { - $fields = UserField::where(['private' => !$only_public_fields])->get(); + if (is_bool($only_public_fields)) { + $fields = UserField::where(['private' => !$only_public_fields])->get(); + } else { + $fields = UserField::get(); + } + return $fields->map(function ($field, $_) use ($user) { foreach ($user->fields as $userFieldValue) { if ($userFieldValue->field->slug === $field->slug) {