amir-hossein5/laravel-ip-logger
Composer 安装命令:
composer require amir-hossein5/laravel-ip-logger
包简介
README 文档
README
Mixes getting details of ip and saving it.
Prerequisites
- Laravel
^8.0|^9.0 - PHP 8
- guzzlehttp/guzzle:
^6.3.1|^7.0.1
Installation
composer require amir-hossein5/laravel-ip-logger
and for publishing configuration file:
php artisan vendor:publish --tag ipLogger
Usage
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();
Saving to database
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.
Manually getting details
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(...);
Exception Handling
Except exceptions that when saving to database(e.g, create, updateOrCreate) happens, can be handle by using:
Getting Last Exception That Happened
use AmirHossein5\LaravelIpLogger\Facades\IpLogger; IpLogger::getLastException();
Catching Exceptions Inline
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.
Listening For Exceptions
/** * The event listener mappings for the application. * * @var array */ protected $listen = [ AmirHossein5\LaravelIpLogger\Events\Failed::class => [ IpLoggerFailed::class, ] ];
License
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-07