jeremykenedy /
laravel-auth
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\ViewComposers; |
||
| 4 | |||
| 5 | use App\Models\Theme; |
||
| 6 | use Illuminate\Support\Facades\Auth; |
||
| 7 | use Illuminate\View\View; |
||
| 8 | |||
| 9 | class ThemeComposer |
||
| 10 | { |
||
| 11 | protected $user; |
||
| 12 | protected $theme; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Create a new instance. |
||
| 16 | * |
||
| 17 | * @return void |
||
| 18 | */ |
||
| 19 | public function __construct() |
||
| 20 | { |
||
| 21 | $this->user = Auth::user(); |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Bind data to the view. |
||
| 26 | * |
||
| 27 | * @param View $view |
||
| 28 | * |
||
| 29 | * @return void |
||
| 30 | */ |
||
| 31 | public function compose(View $view) |
||
| 32 | { |
||
| 33 | $theme = null; |
||
| 34 | |||
| 35 | if (Auth::check()) { |
||
| 36 | $user = $this->user; |
||
| 37 | |||
| 38 | if ($user->profile) { |
||
| 39 | $theme = Theme::find($user->profile->theme_id); |
||
| 40 | |||
| 41 | if ($theme->status === 0) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 42 | $theme = Theme::find(Theme::default); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | $view->with('theme', $theme); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |