erp/app/Models/Log.php

47 lines
906 B
PHP
Raw Normal View History

<?php
namespace App\Models;
2022-08-01 14:28:49 +08:00
use App\Models\traits\Filter;
2022-08-01 17:06:43 +08:00
use Illuminate\Support\Facades\Auth;
2022-08-01 14:28:49 +08:00
class Log extends Model
{
2022-08-01 14:28:49 +08:00
use Filter;
2022-08-01 14:28:49 +08:00
//查询字段
public $fieldSearchable = [
2022-08-01 17:06:43 +08:00
'module',
2022-08-01 14:28:49 +08:00
'action',
'target_type',
'target_id',
'target_field',
'user_id',
'created_at',
];
2022-08-01 17:06:43 +08:00
public $fillable = [
'module',
'action',
'target_type',
'target_id',
'target_field',
'before_update',
'after_update',
];
public function setUserIdAttribute($value)
{
$this->attributes['user_id'] = Auth::id();
}
public function add($targetId = 0, $targetField = '')
{
$this->attributes['user_id'] = Auth::id();
$this->attributes['target_id'] = $targetId;
$this->attributes['target_field'] = $targetField;
return $this->save();
}
}