We can start checking relationship existence, I assume this is your Book model now:
class Book extends Model
{
public function authors()
{
return $this->belongsToMany(Author::class, 'authors_to_books');
}
public function illustrators()
{
return $this->belongsToMany(Illustrator::class, 'illustrators_to_books');
}
}
Then the validation rule can be:
[
'title' => ['required', Rule::unique('books')->where(function ($query) use ($data) {
return $query->where('title', $data->title)
->whereHas('authors', fn ($query) => $query->whereKey($data->author_id))
->whereHas('illustrators', fn ($query) => $query->whereKey($data->illustrator_id));
})],
]