| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?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')) {
- $description = $this->input('tsn_number_description');
- // Сохраняем только если есть расшифровка
- if ($description) {
- \App\Models\PricingCode::createOrUpdate(
- \App\Models\PricingCode::TYPE_TSN_NUMBER,
- $this->input('tsn_number'),
- $description
- );
- }
- }
- // Сохраняем/обновляем расшифровку шифра расценки в справочник
- if ($this->filled('pricing_code')) {
- $description = $this->input('pricing_code_description');
- // Сохраняем только если есть расшифровка
- if ($description) {
- \App\Models\PricingCode::createOrUpdate(
- \App\Models\PricingCode::TYPE_PRICING_CODE,
- $this->input('pricing_code'),
- $description
- );
- }
- }
- }
- }
|