Last active
December 25, 2020 16:36
-
-
Save madi-madi/511836d165951c670c91b1107f9fb93b to your computer and use it in GitHub Desktop.
ViewServiceProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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