| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Http\Requests;
- use Illuminate\Foundation\Http\FormRequest;
- class StoreSparePartRequest extends FormRequest
- {
- /**
- * Determine if the user is authorized to make this request.
- */
- public function authorize(): bool
- {
- return hasRole('admin');
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
- */
- public function rules(): array
- {
- return [
- 'article' => 'required|string|max:255',
- 'used_in_maf' => 'nullable|string|max:255',
- 'product_id' => 'nullable|exists:products,id',
- 'note' => 'nullable|string',
- 'purchase_price' => 'nullable|numeric|min:0',
- 'customer_price' => 'nullable|numeric|min:0',
- 'expertise_price' => 'nullable|numeric|min:0',
- 'tsn_number' => 'nullable|string|max:255',
- 'tsn_number_description' => 'nullable|string',
- 'pricing_codes' => 'nullable|array',
- 'pricing_codes.*' => 'nullable|string|max:255',
- 'pricing_codes_descriptions' => 'nullable|array',
- 'pricing_codes_descriptions.*' => 'nullable|string',
- 'min_stock' => 'nullable|integer|min:0',
- ];
- }
- /**
- * Обработка данных после валидации
- */
- protected function passedValidation()
- {
- // Сохраняем/обновляем расшифровку № по ТСН в справочник
- if ($this->filled('tsn_number')) {
- $description = $this->input('tsn_number_description');
- // Сохраняем только если есть расшифровка
- if ($description) {
- \App\Models\PricingCode::createOrUpdate(
- \App\Models\PricingCode::TYPE_TSN_NUMBER,
- $this->input('tsn_number'),
- $description
- );
- }
- }
- // Примечание: сохранение pricing_codes и их расшифровок
- // происходит в контроллере через syncPricingCodes()
- }
- }
|