Files
Verde-Web/app/Http/Requests/SuperAdmin/StoreTenantRequest.php
Developer 34d3466913 feat: Auto-sync LGUs barangays from Overpass API
- Created SyncLguBarangaysJob to query OSM bounding polygons

- Added created event hook in Tenant model to dispatch sync job

- Fixed UI form submission allowing empty PSGC locations

- Added unique constraint handling for LGU contact phone on admin account creation
2026-07-08 10:50:07 +08:00

43 lines
1.9 KiB
PHP

<?php
namespace App\Http\Requests\SuperAdmin;
use App\Models\Tenant;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreTenantRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$isCreate = $this->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'],
];
}
}