我是 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/