Skip to content

Instantly share code, notes, and snippets.

@abdullah353
Created March 6, 2014 05:45
Show Gist options
  • Save abdullah353/9383274 to your computer and use it in GitHub Desktop.
Save abdullah353/9383274 to your computer and use it in GitHub Desktop.
Share Variable with all views: Now I have access to the currently logged in user as $user in all views, and can access anything from it as normal, such as $user->email
class BaseController extends Controller
{
public function __construct()
{
// Fetch the User object, or set it to false if not logged in
if (Sentry::check()) {
$user = User::find(Sentry::getUser()–>id);
}
else {
$user = false;
}
// Sharing is caring
View::share('user', $user);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment