erp/app/Models/Log.php

47 lines
906 B
PHP

<?php
namespace App\Models;
use App\Models\traits\Filter;
use Illuminate\Support\Facades\Auth;
class Log extends Model
{
use Filter;
//查询字段
public $fieldSearchable = [
'module',
'action',
'target_type',
'target_id',
'target_field',
'user_id',
'created_at',
];
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();
}
}