Files
shopit-back/app/Domains/Tenant/Requests/UpdateTenantRequest.php
ncoronel 689d115a8f feat(tenant): reintroduce tenant-specific props and instance values
Restore props support only for the Tenant domain using a tenant-scoped model
instead of the removed generic Prop/Propable implementation.

Add tenant prop definitions and instance values:
- add TenantProp and TenantPropValue models
- add tenant-only data type enum and prop validation rules
- add migrations for tenant_props and tenant_prop_values tables
- persist prop values by tenant_codigo + tenant_prop_codigo

Expose tenant prop management through the Tenant domain:
- add TenantPropController with CRUD endpoints
- add Store/Update request classes for tenant prop definitions
- register tenant-props routes

Re-enable tenant prop syncing and serialization:
- restore createWithProps/updateWithProps flows in Tenant
- validate props on tenant create/update requests
- include collapsed props in TenantResource
- keep the implementation scoped to Tenant without reintroducing polymorphic props

Add coverage for the new tenant prop behavior:
- update bootstrap tenant feature test to assert prop values
- add feature tests for tenant prop creation and validation
2026-06-24 14:50:58 -03:00

66 lines
1.8 KiB
PHP

<?php
namespace App\Domains\Tenant\Requests;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Tenant\Support\TenantDomainNormalizer;
use App\Domains\Tenant\Support\TenantPropRules;
use Closure;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateTenantRequest extends FormRequest
{
protected bool $hasInvalidDomain = false;
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
$rawDomain = $this->input('dominio');
$normalizedDomain = TenantDomainNormalizer::normalize($rawDomain);
$this->hasInvalidDomain = TenantDomainNormalizer::hasValue($rawDomain)
&& $normalizedDomain === null;
$this->merge([
'dominio' => $normalizedDomain,
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
/** @var Tenant|null $tenant */
$tenant = $this->route('tenant');
return [
'codigo' => [
'required',
'string',
'max:255',
Rule::unique('tenants', 'codigo')->ignore($tenant?->id),
],
'nombre' => ['required', 'string', 'max:255'],
'dominio' => [
'bail',
function (string $attribute, mixed $value, Closure $fail): void {
if ($this->hasInvalidDomain) {
$fail("The {$attribute} field must contain a valid domain or URL.");
}
},
'nullable',
'string',
'max:255',
Rule::unique('tenants', 'dominio')->ignore($tenant?->id),
],
...TenantPropRules::sync(),
];
}
}