2016-05-20 8 views
4

私はpublic/themesフォルダにlaravelを新しくしました。私はデフォルトとオレンジという2つのテーマを持っていますが、オレンジと一緒に行きたいですが、キーワードが指定されています。私はThemeviewFinder.phpでこれを変更しようとしていますが、アセットではなくビューにのみ影響しています。助けてくださいテーマ名をデフォルトからlaravelのものに変更するには

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'); 
} 
+0

あなたは、これまで何を試してみましたか?試したコードがあなたの質問に表示されるはずです。 –

+0

私は@ Jを追加しました。 Chomel –

+0

View :: share( 'assets_path'、app( 'assets_path'))でビュー内に「グローバル」変数を共有します。テーマパスを含み、これはBaseContrlloerの__constructメソッドで宣言できます。 –

答えて

0

カスタムミドルウェアを使用してこれを実現できました。私の使用例では、ドメイン名に基づいて別のテンプレート/テーマを表示する必要がありました。

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, 
]; 
関連する問題