feat: implement product variant CRUD operations and tenant configuration seeding

This commit is contained in:
2026-06-29 11:59:07 -03:00
parent 9b7d728117
commit 0206ee2985
10 changed files with 227 additions and 96 deletions

View File

@@ -2,11 +2,10 @@
namespace App\Domains\Tenant\Requests;
use App\Domains\Shared\Rules\ImageOrBase64Rule;
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
@@ -36,51 +35,8 @@ class StoreTenantRequest extends FormRequest
*/
public function rules(): array
{
$logoRule = [
'required',
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;
}
$logoRule = ['required', new ImageOrBase64Rule()];
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')],

View File

@@ -2,12 +2,11 @@
namespace App\Domains\Tenant\Requests;
use App\Domains\Shared\Rules\ImageOrBase64Rule;
use App\Domains\Tenant\Models\Tenant;
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 UpdateTenantRequest extends FormRequest
@@ -42,51 +41,8 @@ class UpdateTenantRequest extends FormRequest
/** @var Tenant|null $tenant */
$tenant = $this->route('tenant');
$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;
}
$logoRule = ['nullable', new ImageOrBase64Rule()];
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' => [