Download the PHP package andaletech/laravel-browser-info without Composer
On this page you can find all versions of the php package andaletech/laravel-browser-info. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andaletech/laravel-browser-info
More information about andaletech/laravel-browser-info
Files in andaletech/laravel-browser-info
Package laravel-browser-info
Short Description A Laravel 5 package that provide an easy way to get useful browser related information (like supported languages, browser name, etc.) from a request.
License MIT
Informations about the package laravel-browser-info
Browser Info
A Laravel 5 package that provide an easy way to get useful browser related information (like supported languages, browser name, etc.) from a request. To elaborate further...
Work in progress...
Installation
Composer
composer require andaletech/laravel-browser-info
In config/app.php add the following line to the aliases section:
'BrowserInfo' => Andaletech\BrowserInfo\BrowserInfoFacade::class,
Basic Usage
$languages = BrowserInfo::getLanguages();
Log::info('Browser info:',
[
'agent' => BrowserInfo::getUserAgent(),
'languages' => $languages()->toArray(),
'support_en_not_strict' => $languages->supports('en'),
'support_en_strict' => $languages->supports('en', true),
'support_fr_not_strict' => $languages->supports('fr'),
'support_fr_strict' => $languages->supports('fr-FR', true),
]
);
Will result in:
Noteworthy Classes
AcceptedLanguage
Encapsulates a single language that the browser accepts. This class allows you to access:
- The two char i18n language code (i.e. en, fr, es).
- The two char i18n country code (i.e. US, FR, ES)
- The q (the preference weight) of the language..
Examples
If a browser sends:
Then
Languages:
Languages is a collection class that inherits from Laravel's . Therefore, it has all the same methods as the Laravel Collection, plus some additional methods. Those methods are as follows.
supports(string $lang, $strict = false)
This method takes a i18n language code string (i.e. 'en', 'fr-FR', 'es-ES') as parameter to determine if the browser supports that language. By default, this method returns when the browser supports the given language regardless of the country and/or variant segment of the language code. For example, accept-language:
Example
If a browser sends:
Then
Available Facades
BrowserInfo
The BrowserInfo facade allows you to easily access informations related to the browser such as the supported languages. The available methods are the following.