I have a code in my controller of Laravel-5.8
public function customers()
{
try {
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$countCustomers = Customers::where('company_id', $userCompany)->count();
$customers = Customers::where('company_id', $userCompany)->orderBy('created_at', 'desc')->take(5)->get();
return view('customers')
->with('countCustomers', $countCustomers)
->with('countCustomers', $countCustomers);
} catch (Exception $exception) {
Session::flash('error', 'Action failed! Please try again');
return back();
}
}
The code counts the numbers of customers and also lists the top 5 customers
route\web.php
Route::get('/customers', 'HomeController@customers')->name('customer-default');
I want to render this code in the layouts\header.php as shown below.
layouts\header.blade
<li class="nav-item dropdown">
<a class="nav-link" data-toggle="dropdown" href="#">
<i class="far fa-bell"></i>
<span class="badge badge-warning navbar-badge">0</span>
</a>
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
<span class="dropdown-item dropdown-header">You have {{$countCustomers}} Customers</span>
<div class="dropdown-divider"></div>
@foreach($customers as $customer)
{
{{ $customer->first_name }},
}
@endforeach
<div class="dropdown-divider"></div>
<a href="#" class="dropdown-item dropdown-footer">See All Notifications</a>
</div>
</li>
But since the header in the layout don't have controller.
How do I achieve this?
Thank you.