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-04 21:54:55 +08:00
|
|
|
try {
|
|
|
|
$theme = setting('general.theme');
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::error($e->getMessage());
|
|
|
|
$theme = 'default';
|
2019-10-30 21:05:18 +08:00
|
|
|
}
|
|
|
|
|
2020-03-04 21:54:55 +08:00
|
|
|
if (!empty($theme)) {
|
|
|
|
Theme::set($theme);
|
|
|
|
}
|
2020-03-02 04:51:00 +08:00
|
|
|
|
2019-10-30 21:05:18 +08:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|