I am trying to make a notification badge show the amount of unread messages a user has. The following works:
// Controller
public function messages()
{
$messages = MessagesController::getMessages();
$newNotificationNumber = MessagesController::getNumberOfNewMessages();
return view('pages.messages', compact('messages'), compact('newNotificationNumber'));
}
My app.blade.php
file is structured like so:
// html stuff
@include('layouts.navbar')
<main class="py-4 bg-white">
<div class="container">
@yield('content')
</div>
</main>
The navbar shows the number like so:
<span class="badge badge-pill badge-primary">{{ $newNotificationNumber ?? '' }}</span>
If I include compact('newNotificationNumber')
in every single controller function my notifications work like I want, but that is tedious and prone to error. Any suggestions?