Edit File: StoreProductRequest.php
<?php namespace App\Http\Requests\Api\Provider\Product; use App\Http\Requests\Api\BaseApiRequest; class StoreProductRequest extends BaseApiRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return true; } /** * Get the validation rules that apply to the request. * * @return array<string, mixed> */ public function rules() { return [ 'name' => 'required|array|size:' . count(config('translatable.locales')), 'name.*' => 'string|max:255', 'description' => 'required|array|size:' . count(config('translatable.locales')), 'description.*' => 'string|max:1000', 'category_id' => ['required', 'exists:categories,id', function ($attribute, $value, $fail) { $category = \App\Models\Category::where('id', $value)->first()->level; if ($category != 3) { $fail(__('apis.category_not_able_hold_products')); } }], 'has_price' => 'required|boolean', 'price' => 'required_if:has_price,1,true|numeric|gt:0', 'price_after_discount' => 'nullable|numeric|gt:0|lt:price', 'provider_id' => 'required|exists:providers,id', 'images' => 'required|array', 'images.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg,webp|max:2048', ]; } public function prepareForValidation() { $this->merge([ 'provider_id' => auth('provider')->id() ]); } public function attributes() { return [ 'has_price' => __('apis.product_type'), 'category_id' => __('apis.sub_category'), ]; } public function messages() { return [ 'price.required_if' => __('apis.product_has_priced_required'), ]; } }
Back to File Manager