I am having a table where I need to make sure that combination of two columns is unique. I am using laravel 5.4, and jsValidation.
here is how the two fields in the migration
$table->unique(['device_id','factory_id']);
and here is the rule I tried in FormRequest
'device_id' => 'unique:materials,device_id,NULL,id,factory_id,' . Input::get('factory_id')
The issue that I am having is that JsValidator is not sending all the parameters in its ajax method. So mostly I will get Input::get('factory_id') in the rule and so I can't implement the check.
How can I achieve my goal?
I have also tried to use the unique_with rule but that also fails. It produces this querry.
select count(*) as aggregate from `abc_devices` where `device_id` = x
// here x is the device_id but the query doesn't add the where clause for
// the factory id... most probably because of the same above problem.
if I print the input by debug(Input::all()); I only see that jsValidator sends two parameters
array:2 [▼
"device_id" => "222"
"_jsvalidation" => "device_id"
]
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire