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 mobile devices and a different one for desktop devices, so in the view controllers I don't need to make any change.

如果在routes文件中设置路径,并且不接触任何视图控制器,那就太好了.有什么 idea 吗?也许只是配置::设置视图路径?

Thanks in advance! :)

推荐答案

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:

<?php

use Jenssegers\Agent\Agent as Agent;
$Agent = new Agent();
// agent detection influences the view storage path
if ($Agent->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),
    .....

似乎很管用,给了你一个完全不同的工作目录.

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

Laravel相关问答推荐

调用字符串上的成员函数

如何在 laravel livewire 中按 bool 值排序数组

语法错误或访问冲突:1115 未知字符集:utf8mb4

Laravel 6 Passport 在错误的凭证上返回 400 Bad request

Carbon(laravel)处理无效日期

Homestead 2.0 多个站点,都链接到同一个 url

找不到列:1054字段列表中的未知列0-Laravel-我的代码中的任何地方都没有0列

Laravel 5.4 - 注册后禁用自动登录

如何在 Laravel 中实现数组类型路由?

Laravel 同步错误

在 Laravel 容器中覆盖单例

Laravel 说 Auth guard [] 没有定义

Laravel 5.4 有时验证规则不起作用

安装后在 Lumen 中找不到页面

如何在 Laravel 视图中找到当前语言?

如何清理 Laravel Bootstrap 缓存配置文件?

如何使用 Laravel 测试授权重定向?

Laravel 数据库模式中的 MediumBlob

Laravel Route 模型与关系绑定

在 Laravel 中软删除父记录时如何软删除相关记录?