$object ]; } /** * @return array */ protected function rules(): array { return [ 'company_segment' => [ 'required', function ($attribute, $obj, $fail) { // $result = SegmentCompany::where('segment_id', $obj->getSegment()->id)->where('company_id', $obj->getCompany()->id)->first(); $result = $obj->getCompany()->segments()->where('segment_id', $obj->getSegment()->id)->first(); Log::info('SegmentCompany: '.json_encode($result)); if (!is_null($result)) { $fail('The segment company already exists'); } }, ] ]; } /** * @return array */ protected function messages(): array { return []; } }