You can create two mobile , desktop folders inside your view folder. Two folders contain the same views (file names only).
├── views | ├── mobile | | ├── main.blade.php | └── desktop | ├── main.blade.php
Then, inside your controller, you can use the folder names to switch between viewing the desktop and mobile device (or any other if you add more).
You only need to allow the request device through PHP. You can do this with this project: http://mobiledetect.net/ .
Your controller now looks like this:
public function getIndex() { $detect = new Mobile_Detect; return View::make( ($detect->isMobile() ? 'mobile' : 'desktop') . '.your-view-name' ); }
It is a good idea to refactor ($detect->isMobile() ? 'mobile' : 'desktop') to a helper / static function. Or register it as a configuration item in the filters before the route.
Sven van zoelen
source share