Skip to content

Commit da2ee4e

Browse files
committed
#15 Theme switcher
1 parent 9dfb1ca commit da2ee4e

File tree

14 files changed

+129
-6
lines changed

14 files changed

+129
-6
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Theme;
4+
5+
use Illuminate\Routing\Controller;
6+
7+
class SwitchThemeController extends Controller
8+
{
9+
protected $defaultTheme;
10+
11+
const AVAILABLE_THEMES = [
12+
'blue' => 'Blue',
13+
'blue-light' => 'Blue Light',
14+
'black' => 'Dark',
15+
'black-light' => 'Light',
16+
'purple' => 'Purple',
17+
'purple-light' => 'Purple Light',
18+
];
19+
/**
20+
* Create a new controller instance.
21+
*
22+
* @return void
23+
*/
24+
public function __construct()
25+
{
26+
$this->defaultTheme = config('adminlte.skin', 'blue');
27+
}
28+
29+
public function switchTheme(string $theme = null)
30+
{
31+
if (!in_array($theme, array_keys(self::AVAILABLE_THEMES))) {
32+
$theme = $this->defaultTheme;
33+
}
34+
$backUrl = redirect()->back()->getTargetUrl();
35+
$cookie = cookie()->forever(config('app.theme.key', 'theme'), $theme);
36+
37+
return redirect($backUrl)->withCookie($cookie);
38+
}
39+
}

app/Http/Middleware/RoutePermissionMiddleware.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
class RoutePermissionMiddleware
88
{
9+
10+
protected $exclude = [
11+
'theme.switch'
12+
];
913
/**
1014
* Handle an incoming request.
1115
*
@@ -17,7 +21,7 @@ public function handle($request, Closure $next)
1721
{
1822
$permission = $request->route()->getName();
1923

20-
if (!$request->user()->can($permission)) {
24+
if (!in_array($permission, $this->exclude) && !$request->user()->can($permission)) {
2125
abort(403);
2226
}
2327

config/app.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@
127127

128128
'log_level' => env('APP_LOG_LEVEL', 'debug'),
129129

130+
/*
131+
* Theme
132+
*/
133+
'theme' => [
134+
'key' => 'theme',
135+
],
136+
130137
/*
131138
|--------------------------------------------------------------------------
132139
| Autoloaded Service Providers

public/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/css/skin-black.css

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/* Top Menu */
2+
.skin-black .main-header,
3+
.skin-black .main-header {
4+
background-color: #303030;
5+
}
26
.skin-black .main-header .logo,
37
.skin-black .main-header .logo:hover {
48
background-color: #303030;
@@ -57,7 +61,7 @@
5761
}
5862
.skin-black .label-primary {
5963
background-color: #814e23 !important;
60-
color: #ffffff !important;
64+
color: #e0e0e0 !important;
6165
}
6266
.skin-black .content-wrapper {
6367
background-color: #222222;
@@ -96,7 +100,7 @@
96100
border-color: #9ea7ac;
97101
}
98102
.skin-black .select2-container--default .select2-selection--multiple,
99-
.skin-black .select2-container--default .select2-selection--single{
103+
.skin-black .select2-container--default .select2-selection--single {
100104
background-color: #636b6f;
101105
border-color: #80898e;
102106
}
@@ -113,3 +117,21 @@
113117
border: 1px solid #80898e;
114118
width: 100%
115119
}
120+
.skin-black .pagination>li>a,
121+
.skin-black .pagination>li>span {
122+
background-color: #636b6f;
123+
border-color: #80898e;
124+
color: #e0e0e0;
125+
}
126+
.skin-black .pagination>.active>a,
127+
.skin-black .pagination>.active>span {
128+
background-color: #d5833c;
129+
border-color: #d5833c;
130+
color: #ffffff;
131+
}
132+
.skin-black .pagination>li>a:hover,
133+
.skin-black .pagination>li>span:hover {
134+
background-color: #814e23;
135+
border-color: #80898e;
136+
color: #e0e0e0;
137+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* Top Menu */
2+
.skin-blue-light .main-header,
3+
.skin-blue-light .main-header {
4+
background-color: #367fa9;
5+
}

resources/assets/css/skin-blue.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* Top Menu */
2+
.skin-blue .main-header,
3+
.skin-blue .main-header {
4+
background-color: #367fa9;
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Top Menu */
2+
.skin-purple-light .main-header,
3+
.skin-purple-light .main-header {
4+
background-color: #555299;
5+
}
6+
.skin-purple-light a, .skin-purple a:hover {
7+
color: #555299;
8+
}
9+
.skin-purple-light .btn-primary {
10+
background-color: #605ca8;
11+
color: #ffffff;
12+
}
13+
.skin-purple-light .label-primary {
14+
background-color: #605ca8 !important;
15+
color: #ffffff;
16+
}

resources/assets/css/skin-purple.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* Top Menu */
2+
.skin-purple .main-header,
3+
.skin-purple .main-header {
4+
background-color: #555299;
5+
}
16
.skin-purple a, .skin-purple a:hover {
27
color: #555299;
38
}

resources/assets/sass/app.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
// Custom themes
1818
@import "../css/backpack.base.css";
1919
@import "../css/skin-purple.css";
20+
@import "../css/skin-purple-light.css";
2021
@import "../css/skin-black.css";
22+
@import "../css/skin-blue.css";
23+
@import "../css/skin-blue-light.css";

0 commit comments

Comments
 (0)