<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SystemLog extends Model
{
    protected $table = 'logs';

    protected $guarded = [];

    protected $casts = [
        'content' => 'json',
    ];

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    public static function set($data, $content = null)
    {
        return static::create([
            'user_id' => auth()->user()->id,
            'ip' => request()->ip(),
            'record' => $data,
            'content' => $content
        ]);
    }
}
