- Updated ProductVariantService to handle multiple photo keys and URLs. - Introduced FileUploadMultiple component for uploading multiple images. - Modified product creation and editing forms to accommodate multiple photos. - Adjusted data structures in product drafts and tests to reflect changes in photo handling. - Enhanced image preview modal to navigate through multiple images.
58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Master\Product;
|
|
|
|
use App\Enums\PriceType;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ProductVariantRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function prepareForValidation(): void
|
|
{
|
|
$prices = $this->prices;
|
|
if (is_array($prices)) {
|
|
foreach ($prices as $i => $price) {
|
|
if (isset($price['price']) && is_string($price['price'])) {
|
|
$this->request->set("prices.$i.price", (int) str_replace('.', '', $price['price']));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:200'],
|
|
'stock' => ['required', 'integer', 'min:0'],
|
|
'reject_stock' => ['required', 'integer', 'min:0'],
|
|
'retail_stock' => ['required', 'integer', 'min:0'],
|
|
'photo_keys' => ['required', 'array', 'min:1', 'max:5'],
|
|
'photo_keys.*' => ['required', 'string', 'max:500'],
|
|
'prices' => ['required', 'array', 'size:9'],
|
|
'prices.*.type' => ['required', Rule::in(PriceType::values())],
|
|
'prices.*.price' => ['required', 'integer', 'min:0'],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => 'Nama Varian',
|
|
'stock' => 'Stok Bagus',
|
|
'reject_stock' => 'Stok Reject',
|
|
'retail_stock' => 'Stok Ecer',
|
|
'photo_keys' => 'Foto',
|
|
'photo_keys.*' => 'Foto',
|
|
'prices' => 'Harga',
|
|
'prices.*.type' => 'Tipe Harga',
|
|
'prices.*.price' => 'Harga',
|
|
];
|
|
}
|
|
}
|