Skip to Main Content

Laravel: Access the Logged-in User's ID in Your Master Pages

If you are searching for a way to access the current user's ID in you master pages, adding a view creator to your BaseController does the trick. This will make the variable $current_user available in all master pages contained in the views/layouts directory.

class BaseController extends Controller {
    protected function setupLayout() {
       
View::creator('layouts.*', function($view) {
          $view->with('current_user', Auth::id());
        });
       if ( ! is_null($this->layout)) {
          $this->layout = View::make($this->layout);
       }
    }
}

Most RecentRSS

ArchiveRSS

March 2016 (1)
January 2016 (1)
September 2015 (1)
May 2015 (1)
April 2015 (1)
March 2015 (1)
February 2015 (2)
January 2015 (5)
September 2014 (2)
August 2014 (4)
July 2014 (1)
March 2014 (1)
November 2013 (3)
September 2013 (3)
July 2013 (6)
June 2013 (1)
May 2013 (1)
March 2013 (2)
February 2013 (3)
January 2013 (4)