Files
ai-web/app/Http/Requests/Admin/ToolRequest.php
jiangdong.cheng aa16c9f8c2
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
init
2026-02-11 17:28:36 +08:00

50 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests\Admin;
use App\Enums\EntityStatus;
use App\Enums\SourceLevel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ToolRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$toolId = $this->route('tool')?->id;
return [
'category_id' => ['nullable', 'integer', 'exists:categories,id'],
'source_id' => ['nullable', 'integer', 'exists:sources,id'],
'name' => ['required', 'string', 'max:160'],
'slug' => ['required', 'string', 'max:190', Rule::unique('tools', 'slug')->ignore($toolId)],
'summary' => ['required', 'string', 'max:260'],
'description' => ['nullable', 'string'],
'official_url' => ['nullable', 'url', 'max:2048'],
'logo_url' => ['nullable', 'url', 'max:2048'],
'pricing_type' => ['required', 'string', 'max:32'],
'platform' => ['nullable', 'string', 'max:64'],
'language' => ['nullable', 'string', 'max:64'],
'has_api' => ['nullable', 'boolean'],
'source_level' => ['required', Rule::in(array_column(SourceLevel::cases(), 'value'))],
'last_verified_at' => ['nullable', 'date'],
'status' => ['required', Rule::in(array_column(EntityStatus::cases(), 'value'))],
'is_stale' => ['nullable', 'boolean'],
'stale_note' => ['nullable', 'string'],
'alternative_tool_id' => ['nullable', 'integer', 'exists:tools,id'],
'seo_title' => ['nullable', 'string', 'max:180'],
'seo_description' => ['nullable', 'string', 'max:320'],
'h1' => ['nullable', 'string', 'max:180'],
'canonical_url' => ['nullable', 'url', 'max:2048'],
'published_at' => ['nullable', 'date'],
];
}
}