I have a controller where I get the unread comments on the projects of the logged in user. Now my problem is I need this data in my nav partial to show it on all my views. But unfortunately this does not work.
Here's my route:
Route::get('/', 'KlantController@getUnreads');
Here's my function in my KlantController
public function getUnreads(){
$uid = Auth::user()->id;
$projects = User::find($uid)->projects;
//comments
if (!empty($projects)) {
foreach ($projects as $project) {
$comments_collection[] = $project->comments;
}
}
if (!empty($comments_collection)) {
$comments = array_collapse($comments_collection);
$unreads = collect($comments)->where('unread', "1")->count();
}
return view('partials.nav', $unreads);
}
And here's where I use the data in my partial.
@if($unreads > 0)
<span class="label label-danger">{{ $unreads }}</span>
@endif
Annoying enough this gives me multiple times the following error:
Undefined variable: unreads (View: /var/www/resources/views/partials/nav.blade.php)
Anyone has any idea how I can fix this? Any help is appreciated!
Many thanks in advance :)
