Initial commit: Laravel Blog API

This commit is contained in:
2026-05-28 13:50:28 -03:00
commit 8f0ba684fc
71 changed files with 12646 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class CategoryRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules(): array
{
$categoryId = $this->route('category')?->id;
$nameRule = $this->isMethod('post') ? 'required' : 'sometimes';
return [
'name' => [$nameRule, 'string', 'max:255'],
'slug' => [
'nullable',
'string',
'max:255',
'alpha_dash:ascii',
Rule::unique('categories', 'slug')->ignore($categoryId),
],
'description' => ['nullable', 'string'],
];
}
/**
* Get custom attributes for validator errors.
*
* @return array<string, string>
*/
public function attributes(): array
{
return [
'name' => 'nome',
'slug' => 'slug',
'description' => 'descrição',
];
}
}