55 lines
1.0 KiB
PHP
55 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class DownloadLog extends Model
|
|
{
|
|
/**
|
|
* 表示模型不使用 created_at 和 updated_at 时间戳
|
|
* 因为我们使用自定义的 downloaded_at 字段
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $timestamps = false;
|
|
|
|
/**
|
|
* 可批量赋值的属性
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'document_id',
|
|
'user_id',
|
|
'downloaded_at',
|
|
'ip_address',
|
|
];
|
|
|
|
/**
|
|
* 应该被转换为日期的属性
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $casts = [
|
|
'downloaded_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 获取下载日志关联的文档
|
|
*/
|
|
public function document(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Document::class);
|
|
}
|
|
|
|
/**
|
|
* 获取下载日志关联的用户
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
}
|