Skip to content

Instantly share code, notes, and snippets.

@chasecmiller
Created November 23, 2021 16:11
Show Gist options
  • Save chasecmiller/137bb7e194f3e780b94cd7eed043af12 to your computer and use it in GitHub Desktop.
Save chasecmiller/137bb7e194f3e780b94cd7eed043af12 to your computer and use it in GitHub Desktop.
Share user to all views in Laravel
/**
* This is a dead simple way to share your current user within all views in a traditional website.
* Make sure you are importing Illuminate\Support\Facades\View into your AppServiceProvider,
* then add this to the boot method. Once you do that, you can use the $user variable at
* any point in the view to get your currently authenticated view.
*/
View::share('user', \Auth::user());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment