| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace App\Http\Requests;
- use App\Services\Access\AccessService;
- use Illuminate\Foundation\Http\FormRequest;
- class StoreProductRequest extends FormRequest
- {
- /**
- * Determine if the user is authorized to make this request.
- */
- public function authorize(): bool
- {
- if (!auth()->check()) {
- return false;
- }
- if (!$this->routeIs('catalog.store')) {
- return true;
- }
- $requiredFields = [
- 'article',
- 'name_tz',
- 'type_tz',
- 'nomenclature_number',
- 'sizes',
- 'manufacturer',
- 'unit',
- 'type',
- 'product_price',
- 'installation_price',
- 'total_price',
- 'manufacturer_name',
- ];
- $access = app(AccessService::class);
- foreach ($requiredFields as $field) {
- if (!$access->canUpdateField($this->user(), 'catalog', $field)) {
- return false;
- }
- }
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array
- */
- public function rules(): array
- {
- $rules = [
- 'article' => 'required|string',
- 'name_tz' => 'required|string',
- 'type_tz' => 'required|string',
- 'nomenclature_number' => 'required|string',
- 'sizes' => 'required|string',
- 'manufacturer' => 'required|string',
- 'unit' => 'required|string',
- 'type' => 'required|string',
- 'product_price' => 'required|numeric',
- 'installation_price' => 'required|numeric',
- 'total_price' => 'required|numeric',
- 'manufacturer_name' => 'required|string',
- 'note' => 'nullable|string',
- 'passport_name' => 'nullable|string',
- 'statement_name' => 'nullable|string',
- 'service_life' => 'nullable|string',
- 'certificate_number' => 'nullable|string',
- 'certificate_date' => 'nullable|string',
- 'certificate_issuer' => 'nullable|string',
- 'certificate_type' => 'nullable|string',
- 'weight' => 'nullable|numeric',
- 'volume' => 'nullable|nullable',
- 'places' => 'nullable|integer',
- ];
- $access = app(AccessService::class);
- foreach (array_keys($rules) as $field) {
- if (!$access->canUpdateField($this->user(), 'catalog', $field)) {
- unset($rules[$field]);
- }
- }
- return $rules;
- }
- }
|