Support the ongoing development of Laravel.io →
Database Validation Laravel.io

I'm trying to validate unique title for specific book_id it means is should be unique only specific record.

table: questions

$title = this is question 1

$book_id = 12

TRUE = if question not posted for $book_id = 12, user can post same question.

Display Error = if question posted for $book_id = 12, user not able to post.

This is what I tried so far "required|unique:questions,question,book_id".$book_id, "required|unique:questions,question,book_id,!".$book_id, "required|unique:questions,question,NULL,id,book_id,".!$book_id,

Last updated 3 years ago.
0

I think because you're trying to look up the database to see if a question has been posted for $book_id = 12 that you might want to take a look at the Exist(Database) validation method.

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

JeffSh jeffsh Joined 4 Jan 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.