定制 jeremykenedy/laravel-ip-capture 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jeremykenedy/laravel-ip-capture

最新稳定版本:v1.1.0

Composer 安装命令:

composer require jeremykenedy/laravel-ip-capture

包简介

A Laravel package to automatically capture and track IP addresses on Eloquent model actions such as signup, login, update, and deletion.

README 文档

README

Laravel IP Capture

A Laravel package to automatically capture and track IP addresses on Eloquent model actions such as signup, login, update, and deletion.

Total Downloads Latest Stable Version Tests StyleCI License: MIT

Table of Contents

Features

  • Automatic IP capture on model events (signup, login, update, delete)
  • Tracks 6 configurable IP columns per model
  • Simple trait-based integration with any Eloquent model
  • Proxy and load balancer aware (Cloudflare, X-Forwarded-For, etc.)
  • Optional IP hashing for privacy compliance (SHA-256 or custom algorithm)
  • Fluent interface for chaining multiple IP captures
  • Configurable column names and enable/disable per column
  • Publishable config, migrations, and translations

Requirements

Dependency Version
PHP ^8.2 | ^8.3
Laravel ^10.0 | ^11.0 | ^12.0 | ^13.0

Installation

composer require jeremykenedy/laravel-ip-capture

Publish the config file:

php artisan vendor:publish --tag=ip-capture-config

Publish and run the migration:

php artisan vendor:publish --tag=ip-capture-migrations
php artisan migrate

Configuration

The config file is published to config/ip-capture.php.

Option Type Default Description
enabled bool true Enable or disable IP capture globally
null_ip string '0.0.0.0' Fallback value when IP cannot be determined
trust_proxies bool true Use Laravel trusted proxy headers first
hash bool false Hash IP addresses before storage
hash_algo string 'sha256' Hashing algorithm (any algo supported by hash())
columns array see below Enable/disable individual IP columns

Default Columns

Column Default
signup_ip_address true
signup_confirmation_ip_address true
signup_sm_ip_address true
admin_ip_address true
updated_ip_address true
deleted_ip_address true

Environment variables:

IP_CAPTURE_ENABLED=true
IP_CAPTURE_NULL_IP=0.0.0.0
IP_CAPTURE_TRUST_PROXIES=true
IP_CAPTURE_HASH=false
IP_CAPTURE_HASH_ALGO=sha256

Usage

Add the Trait

Add the CapturesIp trait to your User model (or any Eloquent model):

use Jeremykenedy\LaravelIpCapture\Traits\CapturesIp;

class User extends Authenticatable
{
    use CapturesIp;
}

Available Methods

Method Description
captureIp() Returns the current client IP as a string
setSignupIp() Sets the signup IP address column
setSignupConfirmationIp() Sets the signup confirmation IP column
setSocialSignupIp() Sets the social media signup IP column
setAdminIp() Sets the admin action IP column
setUpdatedIp() Sets the updated IP column
setDeletedIp() Sets the deleted IP column
setIpColumn(string $column) Sets a specific IP column by name
getIpColumns() Returns all populated IP columns as an array

All setter methods return static for fluent chaining:

$user->setSignupIp()->setAdminIp()->save();

Custom Columns

Add a custom column to the config:

'columns' => [
    'signup_ip_address'  => true,
    'custom_ip_address'  => true,  // your custom column
],

Then use setIpColumn() to capture:

$user->setIpColumn('custom_ip_address');

IP Hashing

Enable hashing for privacy compliance:

IP_CAPTURE_HASH=true
IP_CAPTURE_HASH_ALGO=sha256

When enabled, all captured IPs are hashed before storage. This is a one-way operation.

Testing

composer test

Or run Pest directly:

./vendor/bin/pest --ci

License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固