Jak zjistit typ zařízení(android, ios, web) pomocí laravel pas api?

0

Otázka

Já se snažím najít typ zařízení (např android, iOS nebo webové prohlížeče) v mém laravel Pas api pro uložení záznamu do databáze, ale to se zdá nemožné, aby to udělat. Prosím, naznačují mi, jak najít typ zařízení.

laravel
2021-11-24 05:35:13
1
0

Odhalování Tohoto trochu typ je opravdu složitý úkol, chtěl bych navrhnout použití MobileDetect nebo jiné Laravel balíčky pro to.

composer require mobiledetect/mobiledetectlib

patří závislost v composer.json soubor

{
    "require": {
        "mobiledetect/mobiledetectlib": "^2.8"
    }
}

A funkcí -

// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
 
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
 
}
 
// Any tablet device.
if( $detect->isTablet() ){
 
}
 
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
 
}
 
// Check for a specific platform with the help of the magic methods:
if( $detect->isiOS() ){
 
}
 
if( $detect->isAndroidOS() ){
 
}
 
// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->is('Chrome')
$detect->is('iOS')
$detect->is('UC Browser')
// [...]
 
// Batch mode using setUserAgent():
$userAgents = array(
'Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19',
'BlackBerry7100i/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/103',
// [...]
);
foreach($userAgents as $userAgent){
 
  $detect->setUserAgent($userAgent);
  $isMobile = $detect->isMobile();
  $isTablet = $detect->isTablet();
  // Use the force however you want.
 
}
 
// Get the version() of components.
// WARNING: this method is in BETA, some keyword properties will change in the future.
$detect->version('iPad'); // 4.3 (float)
$detect->version('iPhone') // 3.1 (float)
$detect->version('Android'); // 2.1 (float)
$detect->version('Opera Mini'); // 5.0 (float)
// [...]

Viz dokumentace se dozvědět více.

2021-11-24 05:52:31

FWIW - github.com/jenssegers/agent je Laravel adaptace MobileDetect
James

Pak pomocí Agenta ( github.com/jenssegers/agent ) by bylo jednodušší, jak se to používá zmínil ( mobiledetect - github.com/serbanghita/Mobile-Detect ) knihovna.
Masudul Hasan Shawon

Děkuji moc, ale To nefunguje s pas api, ale když se snažím to na webovém prohlížeči to funguje dokonale.
rahul

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................