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
This commit is contained in:
18
app/Domains/Tenant/Support/TenantPropDataType.php
Normal file
18
app/Domains/Tenant/Support/TenantPropDataType.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Tenant\Support;
|
||||
|
||||
enum TenantPropDataType: string
|
||||
{
|
||||
case String = 'string';
|
||||
case Number = 'number';
|
||||
case Boolean = 'boolean';
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
}
|
||||
51
app/Domains/Tenant/Support/TenantPropRules.php
Normal file
51
app/Domains/Tenant/Support/TenantPropRules.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Tenant\Support;
|
||||
|
||||
use App\Domains\Tenant\Models\TenantProp;
|
||||
use Closure;
|
||||
|
||||
class TenantPropRules
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function sync(): array
|
||||
{
|
||||
return [
|
||||
'props' => [
|
||||
'sometimes',
|
||||
'array',
|
||||
static function (string $attribute, mixed $value, Closure $fail): void {
|
||||
static::validateExistingProps($attribute, $value, $fail);
|
||||
},
|
||||
],
|
||||
'props.*' => ['nullable'],
|
||||
];
|
||||
}
|
||||
|
||||
protected static function validateExistingProps(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! is_array($value) || $value === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$propCodes = array_map('strval', array_keys($value));
|
||||
$existingPropCodes = TenantProp::query()
|
||||
->whereIn('codigo', $propCodes)
|
||||
->pluck('codigo')
|
||||
->all();
|
||||
|
||||
$missingPropCodes = array_values(array_diff($propCodes, $existingPropCodes));
|
||||
|
||||
if ($missingPropCodes === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fail(sprintf(
|
||||
'The selected %s are invalid for Tenant: %s.',
|
||||
$attribute,
|
||||
implode(', ', $missingPropCodes),
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user