Notification link breaks when registering a new user laravel

Viewed 54

I'm using Laravel's notification table and a foreach loop to get the notifications from the user. so I can change the CSS if there are unread notifications in the navbar. It works fine after the user gets the notification but when registering a new user that has never been notified. It shows HTML with the URL: " href="http://127.0.0.1:8000/notifications/index">NotificationsMy profileProfile settingspost

I want to show the notification link regardless if there are no notifications or not, but I want to change the styling depending on if there are unread notifications or not.

@foreach(auth()->user()->notifications as $notification)
    <a class="@if($notification->read_at<$notification->created_at) px-4 py-2 
        mt-2 ... more css
        @else px-4 py-2 mt-2... more css @endif @endforeach" href="{{ route('notifications.index') }}">Notifications</a>
@endforeach
         
0 Answers
Related