topix-hackademy/loggable-models

一个用于在模型上添加日志的包,以便随时检索

v0.1.1 2017-11-09 15:49 UTC

README

此包提供了一个简单的方法来为Eloquent实体添加日志。

安装

composer require topix-hackademy/loggable-models

在 config/app.php 中

'providers' => [
    ..
    Topix\Hackademy\LoggableModels\Laravel\ServiceProvider::class,
    ..
     ]

然后启动

php artisan vendor:publish

一切准备就绪。

用法

设置您想要记录的模型如下

class Post extends Eloquent implements ModelLogInterface
{
    use ModelLogTrait;


}

现在您可以在该模型的实例上使用任何日志接口中的日志方法

$post->alert($message);

public function emergency($message, array $context = array());
public function alert($message, array $context = array());
public function critical($message, array $context = array());
public function error($message, array $context = array());
public function warning($message, array $context = array());
public function notice($message, array $context = array());
public function info($message, array $context = array());
public function debug($message, array $context = array());

要检索日志,可以使用这些方法复数形式的 get

$post->alerts()

同时,还有用于轻松查询每个级别的数据库的作用域。

scopeHasEmergencies()
...
 
Post::hasEmergencies()->get()