Add multiple unique rules each with it's own table/column?
Feb 2, 2026
5
Level 2
How can I check the uniqueness of multiple fields in one record?
Hello everyone. Here's the task. Four images are added through a form. Each image has a name that is saved in the database. When updating files, I need to delete the previously saved image, upload a new one, and overwrite its name. It's possible that the new file name will match the names of three other files. My question is, how can I check the name of the uploaded file against the names of the other files, each of which is stored in the database? I found an example that only checks one field, and I have four.
$myId = 1;
$validated = $request->validate([
'mydata' => 'unique:table,mydata,' . $myId,
]);
PS: The task requires that file names be changed, which could easily have been solved by assigning a unique name to each newly uploaded file, but alas...
Please or to participate in this conversation.