I want the $year variable to be available in all functions of my PagesController. I tried this code but I didn\'t succeed.
You can create a global singleton within App::before event
App::before(function($request) {
App::singleton('customYear', function(){
$dt = Carbon::parse();
$customYear = $dt->year;
return $customYear;
});
// If you use this line of code then it'll be available in any view
View::share('customYear', app('customYear'));
//To get the same data in any controller you may use:
$customYear = app('customYear');
});