Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sagar001's avatar

How to validate pivot table for unique key value pair?

I have a three tables... first

image -> id, name, timestampe

second

tag -> id, name, timestampe

Image and tag has many to many relation and also have a pivot table

tag_image -> tag_id, image_id

I want to validate the user tag request as they are unique or not... My code so far

$request->validate([
            'tags' => [
	'bail',
                      'required',
                      'string',
                      'unique:image_tag,image_id,tag_id'
]
]);

Problem is user sending ajax request as $request->tags but the unique method needs their ids

0 likes
0 replies

Please or to participate in this conversation.