public function detectDevice() { // @ https://github.com/jenssegers/agent $agent = new Agent(); if ($agent->isMobile() || $agent->isTablet()) { if ($agent->is('android')) { return 'android'; } if ($agent->is('iOS')) { return 'ios'; } return $agent->platform(); } if ($agent->isDesktop()) { if ($agent->is('Windows')) { return 'windows'; } if ($agent->is('OS X')) { return 'OSX'; } return 'desktop'; } }
public function getUA() { // Initialize UA $agent = new Agent(); $browser = $agent->browser(); // Assemble data $data = ['browser' => $browser, 'browser_version' => $agent->version($browser), 'languages' => array($agent->languages()), 'device' => $agent->device(), 'platform' => $agent->platform(), 'is_mobile' => $agent->isMobile(), 'is_tablet' => $agent->isTablet(), 'is_desktop' => $agent->isDesktop(), 'is_robot' => $agent->isRobot(), 'robot_name' => $agent->robot()]; return $data; }
public function getPlatform() { if ($this->agent->isPhone()) { return 'phone'; } if ($this->agent->isTablet()) { return 'tablet'; } if ($this->agent->isMobile()) { return 'mobile'; } if ($this->agent->isDesktop()) { return 'desktop'; } if ($this->agent->isRobot()) { return 'robot'; } return null; }
/** * Record the visitation. * * @param Request $request * @author Cali */ public static function visited(Request $request) { $userAgent = new Agent(); $location = Location::get(); static::create(['referer' => url()->previous(), 'uri' => $request->path(), 'browser' => $userAgent->browser(), 'platform' => $userAgent->platform(), 'device' => $userAgent->device(), 'mobile' => !$userAgent->isDesktop(), 'ip' => $location->ip, 'country' => $location->isoCode, 'city' => $location->cityName, 'robot' => $userAgent->isRobot() ? $userAgent->robot() : null, 'user_id' => $request->user() ? $request->user()->id : null]); }
private function getBodyClass() { $agent = new Agent(); $browser_css_classes = array(); $unsupported = []; if ($mobile = $agent->isMobile()) { $browser_css_classes[] = 'device-mobile'; } if ($tablet = $agent->isTablet()) { $browser_css_classes[] = 'device-tablet'; } if ($iphone = $agent->is('iPhone')) { $browser_css_classes[] = 'device-iphone'; } if ($ipad = $agent->is('iPad')) { $browser_css_classes[] = 'device-ipad'; } $other_browser = $agent->browser(); if ($agent->browser() == "Safari") { $other_browser = false; $browser_css_classes[] = 'browser-safari'; if ($agent->version('Safari') < 5) { $unsupported['browser'] = 'Safari'; } } if ($agent->browser() == "Chrome") { $other_browser = false; $browser_css_classes[] = 'browser-chrome'; $browser_css_classes[] = 'browser-chrome-' . (int) $agent->version('Chrome'); if ($agent->version('Chrome') < 30) { $unsupported['browser'] = 'Chrome'; } } if ($agent->browser() == "Firefox") { $other_browser = false; $browser_css_classes[] = 'browser-firefox'; $browser_css_classes[] = 'browser-firefox-' . (int) $agent->version('Firefox'); if ($agent->version('Firefox') < 25) { $unsupported['browser'] = 'Firefox'; } } if ($browser = $agent->browser() == "IE") { $version = $agent->version("IE"); $version = str_replace('.0', '', $version); $other_browser = false; $browser_css_classes[] = 'browser-ie'; $browser_css_classes[] = 'browser-ie-' . (int) $version; if ((int) $version < 10) { $browser_css_classes[] = 'browser-lt-ie10'; } if ((int) $version < 9) { $unsupported['browser'] = 'Internet Explorer'; } $browser_css_classes[] = 'browser-ie' . $version; } if ($other_browser) { $browser_css_classes[] = 'browser-' . strtolower($other_browser); $version = (int) $agent->version($other_browser); $browser_css_classes[] = 'browser-' . strtolower($other_browser) . '-' . $version; } if ($agent->is('Windows')) { $browser_css_classes[] = 'os-windows'; } if ($agent->is('OS X')) { $browser_css_classes[] = 'os-mac'; } if ($agent->isDesktop()) { $browser_css_classes[] = 'desktop'; } else { //Don't display errors on non-desktop devices $unsupported = []; } $browser_css_classes = implode(' ', $browser_css_classes); return $browser_css_classes; }
<?php /* |-------------------------------------------------------------------------- | Routes File |-------------------------------------------------------------------------- | | Here is where you will register all of the routes in an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ use Jenssegers\Agent\Agent; $agent = new Agent(); if ($agent->isDesktop()) { Route::get('/', function () { return view('pages/main'); }); Route::get('/error', ['as' => 'error', function () { return view('pages/error'); }]); Route::post('grabShots', 'ScreenshotsController@grabShots'); } else { Route::get('/', function () { return view('pages/mobile'); }); } /* |-------------------------------------------------------------------------- | Application Routes |--------------------------------------------------------------------------
/** * Check if the device is a desktop computer. * * @param string $userAgent deprecated * @param array $httpHeaders deprecated * @return bool * @static */ public static function isDesktop($userAgent = null, $httpHeaders = null) { return \Jenssegers\Agent\Agent::isDesktop($userAgent, $httpHeaders); }
/** * Set the user agent field * * @param string $value * @return string */ public function setUserAgentAttribute($value) { $agent = new Agent(); $agent->setUserAgent($value); $this->browser = $agent->browser(); $this->browser_version = $agent->version($this->browser); $this->platform = $agent->platform(); $this->platform_version = $agent->version($this->platform); $this->device = $agent->device() && !$agent->isDesktop() ? $agent->device() : ''; $this->device_type = $agent->isMobile() ? 'mobile' : ($agent->isTablet() ? 'tablet' : ($agent->isDesktop() ? 'desktop' : '')); $this->attributes['user_agent'] = $value; }
public function setUserAgentAttribute($value) { $agent = new Agent(); $agent->setUserAgent($value); if ($agent->isDesktop()) { $platform = 'Desktop'; } elseif ($agent->isMobile()) { if ($agent->isTablet()) { $platform = 'Tablet'; } else { $platform = 'Mobile'; } } $this->attributes['remote_platform'] = $platform; $this->attributes['user_agent'] = $value; }