user()->is_admin) { return true; } if (auth()->user()->school_id) { return true; } return false; } public function rules() { return [ 'student_id' => ['required', 'exists:students,id'], 'audition_id' => ['required', 'exists:auditions,id'], 'for_seating' => ['sometimes', 'boolean'], 'for_advancement' => ['sometimes', 'boolean'], ]; } public function withValidator($validator) { $validator->after(function ($validator) { $auditionId = $this->input('audition_id'); $audition = Audition::find($auditionId); if (! $audition) { $validator->errors()->add('audition_id', 'The selected audition does not exist.'); return; } $currentDate = Carbon::now('America/Chicago')->format('Y-m-d'); if ($audition->entry_deadline < $currentDate) { $validator->errors()->add('entry_deadline', 'The entry deadline for that audition has passed.'); } }); } /** * Prepare the data for validation. */ protected function prepareForValidation() { // Normalize the boolean inputs to 1 or 0 $this->merge([ 'for_seating' => $this->boolean('for_seating'), 'for_advancement' => $this->boolean('for_advancement'), ]); } /** * Get the data after validation and add the "enter_for" array. */ public function validatedWithEnterFor() { $validated = $this->validated(); $enter_for = []; if (! empty($validated['for_seating'])) { $enter_for[] = 'seating'; } if (! empty($validated['for_advancement'])) { $enter_for[] = 'advancement'; } $validated['enter_for'] = $enter_for; return $validated; } }