| 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_code' => 'nullable|string',
- 'pricing_code_description' => 'nullable|string',
- 'min_stock' => 'nullable|integer|min:0',
- ];
- }
- /**
- * Обработка данных после валидации
- */
- protected function passedValidation()
- {
- // Сохраняем расшифровку № по ТСН в справочник, если указана
- if ($this->filled('tsn_number') && $this->filled('tsn_number_description')) {
- \App\Models\PricingCode::createOrUpdate(
- \App\Models\PricingCode::TYPE_TSN_NUMBER,
- $this->input('tsn_number'),
- $this->input('tsn_number_description')
- );
- }
- // Сохраняем расшифровку шифра расценки в справочник, если указана
- if ($this->filled('pricing_code') && $this->filled('pricing_code_description')) {
- \App\Models\PricingCode::createOrUpdate(
- \App\Models\PricingCode::TYPE_PRICING_CODE,
- $this->input('pricing_code'),
- $this->input('pricing_code_description')
- );
- }
- }
- }
|