Files
KanbanGit/app/Http/Requests/StoreProjectRequest.php
T
Twyco 73cee8178f
linter / quality (pull_request) Successful in 2m28s
tests / ci (8.4) (pull_request) Successful in 1m22s
Enforce request validation style rules
2026-04-11 19:44:21 +02:00

50 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Arr;
use Illuminate\Validation\Rule;
class StoreProjectRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
protected function prepareForValidation(): void
{
$key = Arr::get($this->all(), 'key');
if ($key !== null) {
$this->merge([
'key' => strtoupper(trim((string) $key)),
]);
}
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'key' => [
'required',
'string',
'max:5',
'regex:/^[A-Z0-9]+$/',
Rule::unique('projects', 'key'),
],
'name' => ['required', 'string', 'max:255'],
];
}
}