How to validate the uniqueness of combined column value in the nested array?
The input data is
$request = [
[id, vol, number],
[id2, vol2, number2],
...
];
The combination of vol and number must be unique with the data in magazines
table.
id | vol | number
------------------
0 | 001 | 0001
1 | 001 | 0002
2 | 002 | 0001
Here's what my code looks like for now.
$validatedRequest = $request->validate([
'*.id' => ['required', 'string'],
'*.vol' => ['required', 'string'],
'*.number' => ['required', 'string'], //need to add some rule here, I guess
]);
I've read the docs about how to validate nested array data with Rule::forEach()
and also read the tutorial on how to validate the uniqueness on multiple column. However, I still cannot figure the way to access the *.vol
data when creating rule for number
.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire