Edit File: PostGroupsRequest.php
<?php namespace App\Http\Requests\Api\StoreProduct; 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 PostGroupsRequest 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_ids'=>'required', 'product_id' =>'required', ]; } public function withValidator(Validator $validator){ $validator->after(function ($validator) { $properties = collect(json_decode($this->productfeatures_ids)) ->pluck('properties')->toArray(); $normalizedProperties = array_map(function ($nestedArray) { sort($nestedArray); // Sort the array to ensure consistent order return $nestedArray; }, $properties); $serializedProperties = array_map('serialize', $normalizedProperties); if(!(count($serializedProperties) === count(array_unique($serializedProperties)))){ $validator->errors()->add('productfeatures_ids', __('stores_dashboard.sama_feature')); } }); } protected function failedValidation(Validator $validator) { throw new HttpResponseException($this->requestFailsReturn($validator)); } }
Back to File Manager