From a5ca805ab1abb93723dc8d502f6bb8472897ca68 Mon Sep 17 00:00:00 2001 From: Ariel Vallese Date: Sun, 4 Sep 2016 22:51:46 -0300 Subject: [PATCH] Remove session access from controller constructor Prevents sticking to bad practice and stages enhancement for L5.3 Discussion: https://github.com/laravel/framework/issues/15072#issuecomment-242769373 --- app/Http/Controllers/Controller.php | 4 +--- .../User/UserPreferencesController.php | 15 +++------------ app/Providers/ComposerServiceProvider.php | 2 +- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 14f22591..6bd8eff6 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -13,8 +13,6 @@ class Controller extends BaseController public function __construct() { - view()->share('isGuest', auth()->guest()); - view()->share('signedIn', auth()->check()); - view()->share('user', auth()->user()); + // } } diff --git a/app/Http/Controllers/User/UserPreferencesController.php b/app/Http/Controllers/User/UserPreferencesController.php index ef0024e7..ed88fb26 100644 --- a/app/Http/Controllers/User/UserPreferencesController.php +++ b/app/Http/Controllers/User/UserPreferencesController.php @@ -8,15 +8,6 @@ class UserPreferencesController extends Controller { - protected $user; - - public function __construct() - { - parent::__construct(); - - $this->user = auth()->user(); - } - public function getPreferences() { logger()->info(__METHOD__); @@ -24,7 +15,7 @@ public function getPreferences() // BEGIN $parameters = config()->get('preferences.App\Models\User'); - $preferences = $this->user->preferences; + $preferences = auth()->user()->preferences; return view('user.preferences.edit', compact('preferences', 'parameters')); } @@ -60,13 +51,13 @@ protected function setUserPreferences($preferences) foreach ($mergedPreferences as $key => $value) { logger()->info(sprintf( "set preference: UserId:%s key:%s='%s' type:%s", - $this->user->id, + auth()->user()->id, $key, $value, $parameters[$key]['type'] )); - $this->user->pref($key, $value, $parameters[$key]['type']); + auth()->user()->pref($key, $value, $parameters[$key]['type']); } } } diff --git a/app/Providers/ComposerServiceProvider.php b/app/Providers/ComposerServiceProvider.php index 5241ff59..363429d2 100644 --- a/app/Providers/ComposerServiceProvider.php +++ b/app/Providers/ComposerServiceProvider.php @@ -22,7 +22,7 @@ public function boot() ); view()->composer( - ['layouts.app', 'layouts.user'], \App\Http\ViewComposers\AuthComposer::class + ['*'], \App\Http\ViewComposers\AuthComposer::class ); view()->composer(