0

I have a site and I have hosted the site in shared hosting. The thing is it looks great in PC but doesn't look that good in mobile devices. I know I can make it look good with media queries, but I want to deliver the user with a whole new experience. I have seen the thing in Facebook when I open it in PC, it just works good and when I open it in mobile device (cell phone) it asks me to download it for the cell phone. So, how does it know if my device is Android or iOS or PC? I want to do the very same thing in my site. I have a site made with Laravel and in the view I have:

Route::get('/', 'PagesController@index');

And in my controller what I want to do is:

<?php
  if(getDevice($device) === "android"){
      return "mobile_view";
  }else{
    return "pc_view";
  }
?>

So, is there a function in php or Laravel to do that?

michaelitoh
  • 2,164
  • 11
  • 24
  • There are a number of other questions/answers about this too. Please do some research and make an attempt. If you get stuck implementing one of the solutions, feel free to post a question that includes the code that you've tried, the expected result, actual result, and what debugging you've already done. – Patrick Q Aug 24 '18 at 14:10

1 Answers1

0

Detecting OS/Browser is really complicated task, Laravel does not have a built in class/functions to do this. There is however a Laravel package to do this.

https://github.com/hisorange/browser-detect

// Determine the user's device type is simple as this:
Browser::isMobile();
Browser::isTablet();
Browser::isDesktop();

if(Browser::isMobile()){
    return "mobile_view";
}else{
    return "pc_view";
}

If you wana get browser details from a user agent other then the current user call the parse function.

$result = Browser::parse('Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14');
ldrrp
  • 538
  • 1
  • 6
  • 24