isMethod('post'); $tenant = $this->route('tenant'); $admin = $tenant ? $tenant->users()->where('role', \App\Models\User::ROLE_ADMIN)->first() : null; $adminEmailRule = $isCreate ? 'unique:users,email' : Rule::unique('users', 'email')->ignore($admin?->id); return [ 'name' => ['required', 'string', 'max:191'], 'short_name' => ['required', 'string', 'max:50'], 'city_municipality_id' => ['required', 'integer', 'exists:cities_municipalities,id'], 'boundary_polygon' => ['required', 'array', 'min:3'], 'boundary_polygon.*.lat' => ['required', 'numeric'], 'boundary_polygon.*.lng' => ['required', 'numeric'], 'theme_color' => ['nullable', 'string', 'regex:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/'], 'logo_path' => ['nullable', 'string', 'max:255'], 'contact_email' => ['required', 'email', 'max:191'], 'contact_phone' => $isCreate ? ['required', 'string', 'max:20', 'unique:users,phone'] : ['required', 'string', 'max:20'], 'status' => ['nullable', Rule::in([Tenant::STATUS_ONBOARDING, Tenant::STATUS_ACTIVE, Tenant::STATUS_SUSPENDED])], 'timezone' => ['nullable', 'string', 'max:100'], // Default Admin Account Info 'admin_email' => $isCreate ? ['required', 'email', 'max:191', 'unique:users,email'] : ['nullable', 'email', 'max:191', $adminEmailRule], 'admin_password' => $isCreate ? ['required', 'string', 'min:8'] : ['nullable', 'string', 'min:8'], ]; } }