l0max/laravel-activity-log
最新稳定版本:v1.0.0
Composer 安装命令:
composer require l0max/laravel-activity-log
包简介
A Laravel package to log and store user activities across the application
关键字:
README 文档
README
A simple package to log user activity in Laravel applications. Admins can view all logs, while users can view only their own logs.
Installation
You can install the package via Composer:
composer require l0max/laravel-activity-log
To publish the configuration file, run the following command:
php artisan vendor:publish --provider="L0MAX\ActivityLog\ActivityLogServiceProvider"
This will publish the config file config/activitylog.php.
Usage
Once the package is installed, you can use the activity log to track user actions. Each time an action is logged, the ActivityLog model stores the user ID and a description of the action.
Example Usage
use L0MAX\ActivityLog\ActivityLog; ActivityLog::create([ 'user_id' => auth()->id(), 'description' => 'User performed some action.', ]);
Viewing Logs
Admins can view all logs, while regular users can view only their own activity logs.
Policy
A policy is included to handle permissions for viewing logs. Here's a simple example of how to control access to activity logs:
namespace L0MAX\ActivityLog\Policies; use App\Models\User; use L0MAX\ActivityLog\ActivityLog; class ActivityLogPolicy { public function view(User $user, ActivityLog $log) { return $user->hasRole('admin') || $user->id === $log->user_id; } }
Database Migrations
To create the activity_logs table, run the migrations:
php artisan migrate
Factory
You can generate test data using the factory provided:
ActivityLog::factory()->create();
Testing
You can run the tests with:
vendor/bin/phpunit
Ensure that you have added the proper testing logic in the tests/Feature/ directory.
Customization
You can customize the package to suit your needs. The following features can be extended:
- Custom log formats
- Additional policies
Security
If you discover any security-related issues, please email ankahdonatus@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-03