init
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

This commit is contained in:
jiangdong.cheng
2026-02-11 17:28:36 +08:00
parent dcb82557c7
commit aa16c9f8c2
162 changed files with 22333 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Admin;
use App\Models\Category;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class CategoryRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$categoryId = $this->route('category')?->id;
return [
'type' => ['required', Rule::in($this->typeOptions())],
'name' => ['required', 'string', 'max:120'],
'slug' => ['required', 'string', 'max:190', Rule::unique('categories', 'slug')->ignore($categoryId)],
'description' => ['nullable', 'string'],
'is_active' => ['nullable', 'boolean'],
];
}
/**
* @return array<int, string>
*/
private function typeOptions(): array
{
$defaults = ['tool', 'model', 'news', 'guide'];
$existing = Category::query()->distinct()->pluck('type')->filter()->values()->all();
return array_values(array_unique([...$defaults, ...$existing]));
}
}