41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin\Manage;
|
|
|
|
use App\Enums\ProductStockQuality;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class RestockRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()->can('restocks.create')
|
|
|| $this->user()->can('restocks.update');
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'stock_type' => ['sometimes', 'required', Rule::in(ProductStockQuality::values())],
|
|
'items' => ['required', 'array', 'min:1'],
|
|
'items.*.product_variant_id' => ['required', 'integer', Rule::exists('product_variants', 'id')],
|
|
'items.*.quantity' => ['required', 'integer', 'min:1'],
|
|
'notes' => ['nullable', 'string', 'max:100'],
|
|
'photo_key' => ['nullable', 'string', 'max:500'],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'stock_type' => 'Jenis Stok',
|
|
'items' => 'Item Produk',
|
|
'items.*.product_variant_id' => 'Varian Produk',
|
|
'items.*.quantity' => 'Jumlah',
|
|
'notes' => 'Keterangan',
|
|
'photo_key' => 'Foto',
|
|
];
|
|
}
|
|
}
|