Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Remove session access from controller constructor
Browse files Browse the repository at this point in the history
Prevents sticking to bad practice and stages enhancement for L5.3

Discussion:

laravel/framework#15072 (comment)
  • Loading branch information
alariva committed Sep 5, 2016
1 parent 8ab017d commit a5ca805
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
4 changes: 1 addition & 3 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
//
}
}
15 changes: 3 additions & 12 deletions app/Http/Controllers/User/UserPreferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,14 @@

class UserPreferencesController extends Controller
{
protected $user;

public function __construct()
{
parent::__construct();

$this->user = auth()->user();
}

public function getPreferences()
{
logger()->info(__METHOD__);

// BEGIN

$parameters = config()->get('preferences.App\Models\User');
$preferences = $this->user->preferences;
$preferences = auth()->user()->preferences;

return view('user.preferences.edit', compact('preferences', 'parameters'));
}
Expand Down Expand Up @@ -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']);
}
}
}
2 changes: 1 addition & 1 deletion app/Providers/ComposerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a5ca805

Please sign in to comment.