我读过如何为视图添加不同的路径或名称空间,但我认为这对我来说不是一个合适的解决方案。我想做的是为移动设备设置一个视图基路径,为桌面设备设置一个不同的视图基路径,所以在视图控制器中我不需要做任何更改。
这将是很好的设置路径在路由文件和不触及任何视图控制器。有什么想法吗?也许只是Config::设置视图路径?
谢谢!)
发布于 2022-05-26 17:05:21
一种使用移动检测类的简单方法
在根路径上运行:composer require mobiledetect/mobiledetectlib
因此,取决于您想要在哪里作出决定:your-app/views/your-view.blade.php还是your-app/routes/web.php
//include the file
use Detection\MobileDetect as MobileDetect;
//instance it
$detect = new Mobile_Detect;
// Any mobile device (less tablets)
if ( $detect->isMobile() && !$detect->isTablet()) {
echo "is mobile, do something";
}
// Any tablet device
elseif( $detect->isTablet() ){
echo "is tablet, do something";
}
// Desktop device
else {
echo "is desktop, do something";
}https://stackoverflow.com/questions/23779088
复制相似问题