From 85962de188043cdfc7996ba25c4e9c232aba2254 Mon Sep 17 00:00:00 2001 From: miguel456 Date: Fri, 8 Apr 2022 17:26:51 +0100 Subject: [PATCH] fix: prevent display of non-existing profiles --- app/Http/Controllers/ProfileController.php | 9 +++ .../views/dashboard/user/directory.blade.php | 60 ++++++++++--------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index d77b028..00059e2 100755 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -62,6 +62,15 @@ class ProfileController extends Controller public function showSingleProfile(User $user) { + + if (is_null($user->profile)) { + + return redirect() + ->back() + ->with('error', "This user doesn't have a profile."); + + } + $socialMediaProfiles = json_decode($user->profile->socialLinks, true); $createdDate = Carbon::parse($user->created_at); diff --git a/resources/views/dashboard/user/directory.blade.php b/resources/views/dashboard/user/directory.blade.php index 81f632b..b18583b 100755 --- a/resources/views/dashboard/user/directory.blade.php +++ b/resources/views/dashboard/user/directory.blade.php @@ -28,48 +28,50 @@
@foreach ($users as $user) -
-
-
-

{{ $user->name }}

-
{{ $user->profile->profileShortBio }}
-
+ @if (!is_null($user->profile)) +
+
+
+

{{ $user->name }}

+
{{ $user->profile->profileShortBio }}
+
-
- @if($user->profile->avatarPreference == 'gravatar') - {{ __('User profile picture') }} - @else - {{ __('User profile picture') }} - @endif -
- +
- -
+ @endif @endforeach