Answer the question
In order to leave comments, you need to log in
Unique fields and validation?
I have a table with a unique combination of fields, in the migration I specified like this -
$table->string('поле1');
$table->integer('поле2');
$table->unique(['поле1', 'поле2']);
Answer the question
In order to leave comments, you need to log in
You take and check the existence of such a combination in the database, it is not clear what exactly the complexity is.
if(Model::where('field1', $field1)->where('field2', $field2)->exists()) {
//нельзя так делать
}
$messages = [
'data.ip.unique' = 'Given ip and hostname are not unique',
];
Validator::make($data, [
'data.ip' => [
'required',
Rule::unique('servers')->where(function ($query) use($ip,$hostname) {
return $query->where('ip', $ip)
->where('hostname', $hostname);
}),
],
],
$messages
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question