- 实现基于 Laravel 11 和 Filament 3.X 的文档管理系统 - 添加用户认证和分组管理功能 - 实现文档上传、分类和权限控制 - 集成 Word 文档自动转换为 Markdown - 集成 Meilisearch 全文搜索引擎 - 实现文档在线预览功能 - 添加安全日志和审计功能 - 完整的简体中文界面 - 包含完整的项目文档和部署指南 技术栈: - Laravel 11.x - Filament 3.X - Meilisearch 1.5+ - Pandoc 文档转换 - Redis 队列系统 - Pest PHP 测试框架
71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Document;
|
|
use App\Models\DownloadLog;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\DownloadLog>
|
|
*/
|
|
class DownloadLogFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = DownloadLog::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'document_id' => Document::factory(),
|
|
'user_id' => User::factory(),
|
|
'downloaded_at' => fake()->dateTimeBetween('-1 year', 'now'),
|
|
'ip_address' => fake()->ipv4(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 指定下载日志使用特定的文档
|
|
*/
|
|
public function forDocument(Document|int $document): static
|
|
{
|
|
$documentId = $document instanceof Document ? $document->id : $document;
|
|
|
|
return $this->state(fn (array $attributes) => [
|
|
'document_id' => $documentId,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 指定下载日志使用特定的用户
|
|
*/
|
|
public function forUser(User|int $user): static
|
|
{
|
|
$userId = $user instanceof User ? $user->id : $user;
|
|
|
|
return $this->state(fn (array $attributes) => [
|
|
'user_id' => $userId,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 指定下载日志使用最近的时间
|
|
*/
|
|
public function recent(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'downloaded_at' => fake()->dateTimeBetween('-7 days', 'now'),
|
|
]);
|
|
}
|
|
}
|