feat: implement tenant management system including database schema, CRUD services, and bootstrap functionality
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Domains\Tenant\Requests;
|
||||
use App\Domains\Tenant\Support\TenantDomainNormalizer;
|
||||
use Closure;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreTenantRequest extends FormRequest
|
||||
@@ -34,6 +36,52 @@ class StoreTenantRequest extends FormRequest
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$logoRule = [
|
||||
'nullable',
|
||||
static function (string $attribute, mixed $value, Closure $fail): void {
|
||||
if ($value instanceof UploadedFile) {
|
||||
$mime = $value->getMimeType();
|
||||
if (! str_starts_with($mime, 'image/')) {
|
||||
$fail("The {$attribute} must be a valid image or SVG.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
if (Str::isUuid($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$payload = trim($value);
|
||||
$declaredMimeType = null;
|
||||
if (preg_match('/^data:(?<mime>[-\w.+\/]+);base64,(?<data>.+)$/s', $payload, $matches) === 1) {
|
||||
$declaredMimeType = strtolower($matches['mime']);
|
||||
$payload = $matches['data'];
|
||||
}
|
||||
$decoded = base64_decode(preg_replace('/\s+/', '', $payload), true);
|
||||
if ($decoded === false || $decoded === '') {
|
||||
$fail("The {$attribute} must be a valid base64 image or SVG.");
|
||||
return;
|
||||
}
|
||||
$finfo = new \finfo(FILEINFO_MIME_TYPE);
|
||||
$mime = $finfo->buffer($decoded);
|
||||
if (! $mime && $declaredMimeType) {
|
||||
$mime = $declaredMimeType;
|
||||
}
|
||||
if (! $mime || ! str_starts_with($mime, 'image/')) {
|
||||
$fail("The {$attribute} must be a valid image or SVG.");
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
$fail("The {$attribute} must be a valid image or SVG.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$fail("The {$attribute} must be a valid file or base64 string.");
|
||||
},
|
||||
];
|
||||
|
||||
return [
|
||||
'codigo' => ['required', 'string', 'max:255', Rule::unique('tenants', 'codigo')],
|
||||
'nombre' => ['required', 'string', 'max:255'],
|
||||
@@ -49,6 +97,12 @@ class StoreTenantRequest extends FormRequest
|
||||
'max:255',
|
||||
Rule::unique('tenants', 'dominio'),
|
||||
],
|
||||
'primary_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||
'secondary_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||
'danger_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||
'header_footer_bg_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||
'header_logo' => $logoRule,
|
||||
'footer_logo' => $logoRule,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user