Created
August 3, 2020 17:16
-
-
Save pravnkay/4ff70b29c195204445e1b4350af0e522 to your computer and use it in GitHub Desktop.
Set global view data in laravel
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
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