如何使用 Laravel 制作自定义主题以及存储主题数据的位置?

How to make a custom theme using Laravel and where to store theme data?

我正在使用 Laravel 构建一个完整的网站,这个问题正面临着我,我想让用户完全控制网站的外观以及无需更改网站布局的能力我的帮助。

但是当我考虑通过数据库这样做时,有几个包含数十列的表格将被添加到颜色和部分旁边,每次用户将在布局样式。

有没有其他方法可以将主题的选项存储在 XML 文件或数据库以外的任何东西中?

** 注意:当我检查 Wordpress 的数据库时,我没有发现任何与主题相关的东西,那么 Wordpress 在哪里存储主题选项?

对于您的 XML 类存储,您可以使用 Laravel 配置。假设您有文件 config/templates.php。在里面你可以有很多东西。

return [
    'default_template' => 'layouts.templates.default',
    'posts' => 'layouts.templates.post',
    'footer' => 'layouts.includes.footer',

    'options' => [
        'full_with' => false,
        'has_footer' => true,
        'background_color' => '#fff',
        'more_keys' => 'key_value'
    ]
];

然后在您的应用中的任何位置都可以获得默认模板,例如

$view = config('templates.default_template'); //will get
return view($view, compact('params'));

要更新密钥,例如 has_footer,您需要

config(['templates.options.has_footer' => false]); //will update

我想这应该能让你入门

简单示例

假设用户更改了默认颜色并输入并提交了表单。你做

public function updateTheme(Request $request) {
    if ( $request->has('background_colour') && $request->background_colour != '' ) {
        config(['templates.options.background_colour' => $request->background_colour]);       
    }
}