arthuryinzhen/php-action-log

Laravel 的行为日志包

dev-master 2018-07-06 03:49 UTC

This package is auto-updated.

Last update: 2024-09-25 17:18:47 UTC


README

Laravel 5 操作日志自动记录

安装

可以通过 Composer 安装 ActionLog 服务提供者,在项目的 composer.json 中要求 arthuryinzhen/php-action-log 包,并将 minimum-stability 设置为 dev(Laravel 5 所需)。

{
    "require": {
       
        "arthuryinzhen/php-action-log": "dev-master"
    },
   
}

使用 composer 添加此包

composer require luoyangpeng/action-log dev-master

使用 composer update 更新包或使用 composer install 安装。

在 Windows 上,您需要在 php.ini 中将 GD2 DLL php_gd2.dll 作为扩展包含在内。

使用方法

要使用 ActionLog 服务提供者,您必须在启动 Laravel 应用程序时注册提供者。主要有两种方法可以做到这一点。

config/app.php 中找到 providers 键并注册 ActionLog 服务提供者。

    'providers' => [
        // ...
        'arthuryinzhen\ActionLog\ActionLogServiceProvider',
    ]

对于 Laravel 5.1+

    'providers' => [
        // ...
        arthuryinzhen\ActionLog\ActionLogServiceProvider::class,
    ]

config/app.php 中找到 aliases 键。

    'aliases' => [
        // ...
        'ActionLog' => 'arthuryinzhen\ActionLog\Facades\ActionLogFacade',
    ]

对于 Laravel 5.1+

    'aliases' => [
        // ...
        'ActionLog' => arthuryinzhen\ActionLog\Facades\ActionLogFacade::class,
    ]

配置

要使用自己的设置,请发布配置。

$ php artisan vendor:publish

config/action-log.php

	return [
	    //填写要记录的日志的模型名称
	    'models' => [
		    '\App\models\User',
        ],
		
		// 填写监视类别, 默认为admin 该参数为auth相关       
        'guards' => [
            'admin',
        ],  
	];

对于 Laravel 5.1+

	return [
	    //填写要记录的日志的模型名称
	    'models' => [
		    \App\models\User::class,
        ],
		
		// 填写监视类别, 默认为admin 该参数为auth相关       
        'guards' => [
            'admin',
        ],  
	];

最后一步

运行: $ php artisan migrate

演示

自动记录操作日志,数据库操作需按如下

update

$users = Users::find(1);
$users->name = "youname";
$users->save();

add

$users = new Users();
$users->name = "youname";
$users->save()

delete

Users:destroy(1);

主动记录操作日志

use ActionLog

ActionLog::createActionLog($type,$content);