feat(catalog): add product variant controller, requests and resources
This commit is contained in:
52
app/Domains/Catalog/Requests/StoreProductVariantRequest.php
Normal file
52
app/Domains/Catalog/Requests/StoreProductVariantRequest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreProductVariantRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'producto_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
Rule::exists('productos', 'id')->where(
|
||||
fn ($query) => $query->where('tenant_codigo', $this->route('tenant')?->codigo)
|
||||
),
|
||||
],
|
||||
'slug' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('productos_variantes', 'slug')->where(
|
||||
fn ($query) => $query->where('producto_id', $this->input('producto_id'))
|
||||
),
|
||||
],
|
||||
'nombre' => ['nullable', 'string', 'max:255'],
|
||||
'stock' => ['sometimes', 'integer', 'min:0'],
|
||||
'descripcion' => ['nullable', 'string'],
|
||||
'precio' => ['required', 'numeric', 'min:0'],
|
||||
'definitions' => ['sometimes', 'array'],
|
||||
'definitions.*.attribute_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
'distinct',
|
||||
Rule::exists('productos_attributes', 'id')->where(
|
||||
fn ($query) => $query->where('tenant_codigo', $this->route('tenant')?->codigo)
|
||||
),
|
||||
],
|
||||
'definitions.*.value' => ['nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
56
app/Domains/Catalog/Requests/UpdateProductVariantRequest.php
Normal file
56
app/Domains/Catalog/Requests/UpdateProductVariantRequest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Requests;
|
||||
|
||||
use App\Domains\Catalog\Models\ProductVariant;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateProductVariantRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var ProductVariant|null $productVariant */
|
||||
$productVariant = $this->route('productVariant');
|
||||
|
||||
return [
|
||||
'producto_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
Rule::exists('productos', 'id')->where(
|
||||
fn ($query) => $query->where('tenant_codigo', $this->route('tenant')?->codigo)
|
||||
),
|
||||
],
|
||||
'slug' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('productos_variantes', 'slug')
|
||||
->ignore($productVariant?->id)
|
||||
->where(fn ($query) => $query->where('producto_id', $this->input('producto_id'))),
|
||||
],
|
||||
'nombre' => ['nullable', 'string', 'max:255'],
|
||||
'stock' => ['sometimes', 'integer', 'min:0'],
|
||||
'descripcion' => ['nullable', 'string'],
|
||||
'precio' => ['required', 'numeric', 'min:0'],
|
||||
'definitions' => ['sometimes', 'array'],
|
||||
'definitions.*.attribute_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
'distinct',
|
||||
Rule::exists('productos_attributes', 'id')->where(
|
||||
fn ($query) => $query->where('tenant_codigo', $this->route('tenant')?->codigo)
|
||||
),
|
||||
],
|
||||
'definitions.*.value' => ['nullable', 'string'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user