Mixes getting details of ip and saving it.
- Laravel
^8.0|^9.0
- PHP 8
- guzzlehttp/guzzle:
^6.3.1|^7.0.1
composer require amir-hossein5/laravel-ip-logger
and for publishing configuration file:
php artisan vendor:publish --tag ipLogger
For just getting details:
use AmirHossein5\LaravelIpLogger\Facades\IpLogger;
IpLogger::getDetails();
Methods for work with details:
method | description |
---|---|
detailsBe() | Writing details manually. |
prepare() | Editting predefined details. |
for Example:
use AmirHossein5\LaravelIpLogger\Facades\IpLogger;
IpLogger::prepare(function ($details) {
return $details + ['test' => 'test'];
})->getDetails();
use AmirHossein5\LaravelIpLogger\Facades\IpLogger;
IpLogger::model(ModelName::class)
->updateOrCreate(
fn ($details) => [
'ip' => $details['query']
],
fn ($details) => [
'continent' => $details['continent'],
'country' => $details['country'],
...
],
);
For saving there are two methods, create
, updateOrCreate
, and work like laravel ones.
By default has been wroten two apis to getting details of ip, ip_api ,and vpn_api. It's settable in config file.
Or if you want to use another api get details manually.
use \AmirHossein5\LaravelIpLogger\Facades\IpLogger;
IpLogger::detailsBe(function () {
return [ ... ];
})->updateOrCreate(...);
Except exceptions that when saving to database(e.g, create, updateOrCreate) happens, can be handle by using:
use AmirHossein5\LaravelIpLogger\Facades\IpLogger;
IpLogger::getLastException();
use AmirHossein5\LaravelIpLogger\Facades\IpLogger;
IpLogger::catch(function ($exception) {
// send mail ...
})...;
You should use this as the first method.
When using this way no event will be dispatch.
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
AmirHossein5\LaravelIpLogger\Events\Failed::class => [
IpLoggerFailed::class,
]
];