gaocheng/actionlog

一个用于操作日志的 Laravel 扩展包

dev-master 2018-06-12 05:26 UTC

This package is not auto-updated.

Last update: 2024-09-19 11:44:34 UTC


README

Laravel 5 操作日志自动记录

安装

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

{
    "require": {
       
        "gaocheng/actionlog": "~1.0"
    },
   
}

或者

使用composer安装此包

composer require gaocheng/actionlog 

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

用法

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

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

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

对于Laravel 5.1+

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

config/app.php中找到aliases键。

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

对于Laravel 5.1+

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

配置

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

$ php artisan vendor:publish

config/actionlog.php

    /*
    |--------------------------------------------------------------------------
    | Package Connection
    |--------------------------------------------------------------------------
    |
    | You can set a different database connection for this package. It will set
    | new connection for models ActionLog. When this option is null,
    | it will connect to the main database, which is set up in database.php
    |
    */

    'connection' => null,

    /*
    |--------------------------------------------------------------------------
    | Package Models
    |--------------------------------------------------------------------------
    |
    | You can set up same models that requires logging. When this option is null,
    | no logging will be done.
    |
    */
    
    'models' => [
        '\App\User',
    ],

最后一步

运行:$ php artisan migrate

演示

自动记录操作日志,数据库操作需按照以下方式

update

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

add

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

delete

Users:destroy(1);

主动记录操作日志

use ActionLog

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

感谢 https://github.com/luoyangpeng/action-log/