Laravel detect mobile/tablet and load correct views

前端 未结 4 1317
有刺的猬
有刺的猬 2020-12-24 00:52

I have read how to add different paths or namespaces for views, but I think this is not a proper solution for me. What I would like to do it\'s to set a view base path for

4条回答
  •  渐次进展
    2020-12-24 01:14

    I'm looking at the same issue here, basically wanting to "bolt on" a directory of mobile views without messing with my controllers (if possible).

    One place to do this may be the config in app/config/views.php:

    isMobile()) {
        // you're a mobile device
        $viewPath = __DIR__.'/../mobile';
    } else {
        // you're a desktop device, or something similar
        $viewPath = __DIR__.'/../views';
    }
    
    
    return array(
        'paths' => array($viewPath),
        .....
    

    seems to work, giving you a completely different directory to work from.

    I'll continue to experiment, as perhaps there will be some overlap between the desktop and mobile includes, but we'll see.

    PS: Agent ~= Mobile_Detect

提交回复
热议问题