Skip to content

Instantly share code, notes, and snippets.

@pravnkay
Created August 3, 2020 17:16
Show Gist options
  • Save pravnkay/4ff70b29c195204445e1b4350af0e522 to your computer and use it in GitHub Desktop.
Save pravnkay/4ff70b29c195204445e1b4350af0e522 to your computer and use it in GitHub Desktop.
Set global view data in laravel
use Illuminate\Auth\Events\Authenticated;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app['events']->listen(Authenticated::class, function ($e) {
view()->share('user', $e->user);
});
// OR Method 2
view()->composer('*', function ($view) {
$view->with('user', auth()->user());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment