singleloginsystem/app/Concerns/ProfileValidationRules.php
= 9b6af8135d refactor: remove unused UI components and factories for cleanup
- Deleted obsolete components (`Choices`, `Input`, `ListItem`, `Table`) and trait (`HasAttributeHelpers`) from the `App\View\Components` namespace.
- Removed `ConnectedAppFactory` as it is no longer utilized in the current workflow.
2026-05-16 09:44:54 +00:00

55 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Concerns;
use App\Models\User;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Unique;
trait ProfileValidationRules
{
/**
* Get the validation rules used to validate user profiles.
*
* @return array<string, array<int, ValidationRule|Unique|string>>
*/
protected function profileRules(?int $userId = null): array
{
return [
'name' => $this->nameRules(),
'email' => $this->emailRules($userId),
];
}
/**
* Get the validation rules used to validate user names.
*
* @return array<int, ValidationRule|array<mixed>|string>
*/
protected function nameRules(): array
{
return ['required', 'string', 'max:255'];
}
/**
* Get the validation rules used to validate user emails.
*
* @return array<int, ValidationRule|Unique|string>
*/
protected function emailRules(?int $userId = null): array
{
return [
'required',
'string',
'email',
'max:255',
null === $userId
? Rule::unique(User::class)
: Rule::unique(User::class)->ignore($userId),
];
}
}