359 Select theme in settings (#423)
* Update composer package versions * Laravel version * Change theme in the admin settings page closes #359 * Fix comment
This commit is contained in:
@@ -4,14 +4,34 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Contracts\Controller;
|
||||
use App\Models\Setting;
|
||||
use Igaster\LaravelTheme\Facades\Theme;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class SettingsController
|
||||
*/
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get a list of themes formatted for a select box
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getThemes(): array
|
||||
{
|
||||
$themes = Theme::all();
|
||||
$theme_list = [];
|
||||
foreach ($themes as $t) {
|
||||
if (!$t || !$t->name || $t->name === 'false') {
|
||||
continue;
|
||||
}
|
||||
$theme_list[] = $t->name;
|
||||
}
|
||||
|
||||
return $theme_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the settings. Group them by the setting group
|
||||
*/
|
||||
@@ -22,6 +42,7 @@ class SettingsController extends Controller
|
||||
|
||||
return view('admin.settings.index', [
|
||||
'grouped_settings' => $settings,
|
||||
'themes' => $this->getThemes(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
22
app/Http/Middleware/SetActiveTheme.php
Normal file
22
app/Http/Middleware/SetActiveTheme.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Igaster\LaravelTheme\Facades\Theme;
|
||||
|
||||
/**
|
||||
* Read the current theme from the settings (set in admin), and set it
|
||||
*/
|
||||
class SetActiveTheme
|
||||
{
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$theme = setting('general.theme');
|
||||
if (!empty($theme)) {
|
||||
Theme::set($theme);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,11 @@
|
||||
/**
|
||||
* User doesn't need to be logged in for these
|
||||
*/
|
||||
use App\Http\Middleware\SetActiveTheme;
|
||||
|
||||
Route::group([
|
||||
'namespace' => 'Frontend', 'prefix' => '', 'as' => 'frontend.',
|
||||
'namespace' => 'Frontend', 'prefix' => '', 'as' => 'frontend.',
|
||||
'middleware' => [SetActiveTheme::class],
|
||||
], function () {
|
||||
Route::get('/', 'HomeController@index')->name('home');
|
||||
Route::get('r/{id}', 'PirepController@show')->name('pirep.show.public');
|
||||
@@ -21,7 +24,7 @@ Route::group([
|
||||
*/
|
||||
Route::group([
|
||||
'namespace' => 'Frontend', 'prefix' => '', 'as' => 'frontend.',
|
||||
'middleware' => ['role:admin|user'],
|
||||
'middleware' => ['role:admin|user', SetActiveTheme::class],
|
||||
], function () {
|
||||
Route::resource('dashboard', 'DashboardController');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user