topix-hackademy / loggable-models
一个用于在模型上添加日志的包,以便随时检索
v0.1.1
2017-11-09 15:49 UTC
Requires
- psr/log: ^1.0
Requires (Dev)
- laracasts/testdummy: ~2.0
- laravel/laravel: ^5.2
- phpunit/phpunit: ^5.4
This package is not auto-updated.
Last update: 2024-09-27 22:58:46 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()