php - 如何将主题名称从默认更改为 laravel 中的任何名称

标签 php laravel themes

我是 public/themes 文件夹中的 laravel 新手 我有两个名为 default 和 orange 的主题 我想使用 orange 但我看不到 default 关键字的指定位置。我试图在 ThemeviewFinder.php 中更改它,但它只影响 View 而不影响 Assets 。请帮助我

public function setActiveTheme($theme)
{

$users = DB::table('config')
                 ->select('activatedTheme')
                 ->where('id', 1)
                 ->get();
    //print_r($users);
    foreach($users as $row){
        $theme = $row->activatedTheme;

    }
   $this->activeTheme = $theme;
    array_unshift($this->paths, $this->basePath.'/'.$theme.'/views');
}

最佳答案

我能够使用自定义中间件实现此目的。在我的用例中,我需要根据域名显示不同的模板/主题。

TemplateMiddleware.php

public function handle($request, Closure $next)
{
    $paths = [];
    $app = app();

    /*
     *  Pull our template from our site name
     */
    $template = Template::where('domain', Request::server('SERVER_NAME'))->first();
    if($template)
    {
        $paths = [
            $app['config']['view.paths.templates'] . DIRECTORY_SEPARATOR . $template->tag
        ];
    }


    /*
     *  Default view path is ALWAYS last
     */
    $paths[] = $app['config']['view.paths.default'];

    /*
     * Overwrite the view finder paths
     */
    $finder = new FileViewFinder(app()['files'], $paths);
    View::setFinder($finder);

    return $next($request);
}

内核.php

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \App\Http\Middleware\TemplateMiddleware::class,
];

关于php - 如何将主题名称从默认更改为 laravel 中的任何名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37340131/

相关文章:

php - SilverStripe 主题无法识别主页主题

themes - 根据安装的 Domino 版本使用 OneUI 主题

java - 在Android中创建JSON ArrayList/JSON对象并发送到PHP

php - 解压 8 字节整数

php - 静态密码在默认的 Laravel 用户工厂中如何工作?

javascript - Bootstrap 多选在 laravel View 中不起作用

php - Laravel 在需要忽略多行的更新方法中验证数组

WPF Office 2007 主题

php - OCI_NO_DATA oci8 oracle 错误

PHP数组操作时内存使用突然增加