2019-10-30 21:05:18 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
2019-11-27 22:19:20 +08:00
|
|
|
use App\Contracts\Middleware;
|
2019-10-30 21:05:18 +08:00
|
|
|
use Closure;
|
|
|
|
use Igaster\LaravelTheme\Facades\Theme;
|
2019-11-27 22:19:20 +08:00
|
|
|
use Illuminate\Http\Request;
|
2020-01-15 02:55:24 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-10-30 21:05:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read the current theme from the settings (set in admin), and set it
|
|
|
|
*/
|
2019-11-27 22:19:20 +08:00
|
|
|
class SetActiveTheme implements Middleware
|
2019-10-30 21:05:18 +08:00
|
|
|
{
|
2019-11-27 22:19:20 +08:00
|
|
|
public function handle(Request $request, Closure $next)
|
2019-10-30 21:05:18 +08:00
|
|
|
{
|
2020-03-02 04:51:00 +08:00
|
|
|
if (!$request->session()->has('theme')) {
|
|
|
|
try {
|
|
|
|
$theme = setting('general.theme');
|
|
|
|
if (empty($theme)) {
|
|
|
|
$theme = 'default';
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error($e->getMessage());
|
|
|
|
$theme = 'default';
|
|
|
|
}
|
2020-01-15 02:55:24 +08:00
|
|
|
|
2020-03-02 04:51:00 +08:00
|
|
|
$request->session()->put('theme', $theme);
|
|
|
|
} else {
|
|
|
|
$theme = $request->session()->get('theme', 'default');
|
2019-10-30 21:05:18 +08:00
|
|
|
}
|
|
|
|
|
2020-03-02 04:51:00 +08:00
|
|
|
Theme::set($theme);
|
|
|
|
|
2019-10-30 21:05:18 +08:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|