Skip to content

Instantly share code, notes, and snippets.

@andyg1
Created March 7, 2016 13:43
Show Gist options
  • Save andyg1/528e6587cacf96e06466 to your computer and use it in GitHub Desktop.
Save andyg1/528e6587cacf96e06466 to your computer and use it in GitHub Desktop.
Include a Blade view template only if there is a logged in user. Useful for including/excluding views and/or partials for things like menus, logout buttons, etc
/*
* Laravel includeIfAuth() function.
*
* Usage: @includeIfAuth($templateName)
*/
\Blade::directive('includeIfAuth', function ($expression) {
if(\Auth::check()) {
return \Blade::compileString("@include({$expression})");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment