mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Companies\Standards\Validators;
|
|
|
|
use App\Classes\General\Abstracts\AbstractValidation;
|
|
use App\Classes\Modules\Companies\DataTransferObjects\CompanySegmentObject;
|
|
use App\Models\SegmentCompany;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CompanyToSegmentValidation extends AbstractValidation
|
|
{
|
|
/**
|
|
* @param CompanySegmentObject $object
|
|
* @return array
|
|
*/
|
|
protected function data($object): array
|
|
{
|
|
return[
|
|
'company_segment' => $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 [];
|
|
}
|
|
|
|
}
|