Themes with package igaster

北战南征 提交于 2019-12-06 15:10:48

Since Sessions in Laravel5 are initiated in the middleware stack you should create your own middleware and place it in the $middleware array in Kernel.php. This is a sample middleware:

class myMiddleware {
    public function handle($request, Closure $next) {

       $themeName = \Session::get('themeName', 'NONE');

          if(\Theme::exists($themeName))
              \Theme::set($themeName);

           return $next($request);
       }

   }

your routes.php could be something like:

Route::get('setTheme/{themeName}', function($themeName){
    Session::put('themeName', $themeName);
    return Redirect::to('/');
});

Route::get('/', function() {
    return Theme::get();  // display your views here....
});

Note that you have to pull the latest version (v1.0.4) for this to work

If you have properly followed the installation instructions (https://github.com/igaster/laravel-theme), you can change the theme like this:

Theme::set('theme-name');

If you want to change the theme by clicking a link, you have to store current theme name somewhere. Most probably you don't want to store it in URI, so I advice you to store it in a session.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!