4a14e83c88
* Update gitignore * Save theme to the session to avoid a lookup #602 * Formatting * Move routes into main service provider * Move Observers into their own service provider
39 lines
946 B
PHP
39 lines
946 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Contracts\Middleware;
|
|
use Closure;
|
|
use Igaster\LaravelTheme\Facades\Theme;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
* Read the current theme from the settings (set in admin), and set it
|
|
*/
|
|
class SetActiveTheme implements Middleware
|
|
{
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
if (!$request->session()->has('theme')) {
|
|
try {
|
|
$theme = setting('general.theme');
|
|
if (empty($theme)) {
|
|
$theme = 'default';
|
|
}
|
|
} catch (\Exception $e) {
|
|
Log::error($e->getMessage());
|
|
$theme = 'default';
|
|
}
|
|
|
|
$request->session()->put('theme', $theme);
|
|
} else {
|
|
$theme = $request->session()->get('theme', 'default');
|
|
}
|
|
|
|
Theme::set($theme);
|
|
|
|
return $next($request);
|
|
}
|
|
}
|