$default) { $this->{$var} = $config->get('brand.mail.'.Str::studly($var), $default); } } public function afterSave() { $this->resetCache(); } public function resetCache() { Cache::forget(self::instance()->cacheKey); } public static function renderCss() { $cacheKey = self::instance()->cacheKey; if (Cache::has($cacheKey)) { return Cache::get($cacheKey); } try { $customCss = self::compileCss(); Cache::forever($cacheKey, $customCss); } catch (Exception $ex) { $customCss = '/* ' . $ex->getMessage() . ' */'; } return $customCss; } protected static function getCssVars() { $vars = [ 'body_bg' => self::BODY_BG, 'content_bg' => self::WHITE_COLOR, 'content_inner_bg' => self::WHITE_COLOR, 'button_text_color' => self::WHITE_COLOR, 'button_primary_bg' => self::PRIMARY_BG, 'button_positive_bg' => self::POSITIVE_BG, 'button_negative_bg' => self::NEGATIVE_BG, 'header_color' => self::HEADER_COLOR, 'heading_color' => self::HEADING_COLOR, 'text_color' => self::TEXT_COLOR, 'link_color' => self::LINK_COLOR, 'footer_color' => self::FOOTER_COLOR, 'body_border_color' => self::BORDER_COLOR, 'subcopy_border_color' => self::BORDER_COLOR, 'table_border_color' => self::BORDER_COLOR, 'panel_bg' => self::BORDER_COLOR, 'promotion_bg' => self::WHITE_COLOR, 'promotion_border_color' => self::PROMOTION_BORDER_COLOR, ]; return $vars; } protected static function makeCssVars() { $vars = static::getCssVars(); $result = []; foreach ($vars as $var => $default) { // panel_bg -> panel-bg $cssVar = str_replace('_', '-', $var); $result[$cssVar] = self::get($var, $default); } return $result; } public static function compileCss() { $parser = new Less_Parser(['compress' => true]); $basePath = base_path('modules/system/models/mailbrandsetting'); $parser->ModifyVars(static::makeCssVars()); $parser->parse(FileHelper::get($basePath . '/custom.less')); return $parser->getCss(); } }