Proje: Okul Platform · Hub: Okul Platform — Conventions
FormRequest Pattern
authorize()
public function authorize(): bool
{
return auth()->check() && auth()->user()->isAdmin();
}- Admin endpoint’ler:
isAdmin()kontrolü - B2B endpoint’ler:
isCustomer()veya sanctum ile
rules() Ayrıştırma
Büyük request’lerde kurallar ayrı metodlara bölünür:
public function rules(): array
{
return array_merge(
$this->generalRules(),
$this->highSchoolRules(), // school_type_id=4 ise zorunlu
$this->featuresRules(), // Etiket, aktivite, tesis validasyonu
);
}prepareForValidation()
Validation öncesi veri manipülasyonu:
protected function prepareForValidation(): void
{
$this->merge(['created_by' => auth()->id()]);
$this->makeUniquePhone('telephone');
$this->makeUniquePhone('notify_gsm');
}Telefon Normalize
$phones = array_unique(array_map(fn($p) => getMaskedPhone($p), $phones));Benzersiz + mask formatı.
Rule::exists Soft Delete Koruması
Rule::exists(Tag::class, 'id')->whereNull('deleted_at')Silinmiş kayıtları validation’da reddeder.
Conditional Rules
'high_school_type_id' => ['required_if:school_type_id,4', ...]Lise (4) seçilmişse lise tipi zorunlu.
Custom Closure Validation
'school_feature_name_id' => [Rule::custom($this->validateFeatureName(...))]SchoolFeatureNameRepositoryInterface üzerinden okul tipine uygun feature validasyonu.
Related
- api-custom-validation-rules — CustomValidationRule (phone/gsm)
- api-phone-number-helpers — getMaskedPhone