1

I'm looking for the best practise to implement user notifications in "app.blade.php" layout.

The Layout should always check for user notifications and I don't want to implement in every Controller.

Thanks for your ideas.

Zoe Edwards
  • 12,999
  • 3
  • 24
  • 43
Smoky
  • 127
  • 1
  • 2
  • 12

1 Answers1

1

Asuming you don’t mean Notifications and your own implementation, then you’d want to use a View Composer:

Create a composer called UserNotificationComposer or similar, add your logic to that, then create a ViewServiceProvider and link them up:

View::composer(
    '*', 'App\Http\View\Composers\UserNotificationComposer'
);

(This is asuming you’re using your own ‘user notifications’, if you’re using the Larvel Notifications, then you don’t need any logic in your controllers.)

Zoe Edwards
  • 12,999
  • 3
  • 24
  • 43
  • I did it in this way `/** * Bootstrap any application services. * * @return void */ public function boot() { view()->composer('layouts.app', function($view){ $view->with('userNotification', UserNotifications::getNotifications()); }); }` – Smoky Mar 08 '19 at 15:20