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

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

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);
}

Kernel.php

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