Skip to content

Instantly share code, notes, and snippets.

@madi-madi
Last active December 25, 2020 16:36
Show Gist options
  • Save madi-madi/511836d165951c670c91b1107f9fb93b to your computer and use it in GitHub Desktop.
Save madi-madi/511836d165951c670c91b1107f9fb93b to your computer and use it in GitHub Desktop.
ViewServiceProvider
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use App\Http\View\Composers\ProfileComposer;
class ViewServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// Using closure based composers...
View::composer('layouts.app', function ($view) {
if (Auth::check()) {
// The user is logged in...
$notifications =auth()->user()->notifications()->select('id','data','created_at','read_at')->get();
$notificationCount = auth()->user()->unreadNotifications()->count();
$view->with(['notifications'=> $notifications,'notificationCount'=>$notificationCount]);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment