Edit File: postProductFeatureProperities.php
<?php namespace App\Http\Requests\Api\StoreProduct; use App\Models\Feature; use App\Models\Properity; use Illuminate\Foundation\Http\FormRequest; use App\Traits\Responses; use Illuminate\Contracts\Validation\Validator; use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Http\Request; use App\Traits\ApiTrait; class postProductFeatureProperities extends FormRequest { use ApiTrait; /** * 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 */ public function rules() { return [ 'productfeatures'=>'required', 'product_id' => 'required', ]; } public function withValidator($validator) { $validator->after(function ($validator) { foreach (json_decode($this->productfeatures) as $productfeatures) { $feature = Feature::find($productfeatures->feature_id); if (!$feature) { $validator->errors()->add('productfeatures', __('stores_dashboard.feature_not_available')); }else{ foreach ($productfeatures->properties as $property) { $property_v = Properity::find($property->id); if (!$property_v) { $validator->errors()->add('productfeatures', __('stores_dashboard.property_not_available')); } break; } } } }); } protected function failedValidation(Validator $validator) { throw new HttpResponseException($this->requestFailsReturn($validator)); } }
Back to File Manager