Is it possible to pass the unique validation method extra where clauses with a variable?
Heres an example:
In my model I have my validation rules.
The Laravel documentation on validation has a sub-section titled, “Adding Additional Where Clauses” in the unique rule section:
You may also specify more conditions that will be added as "where" clauses to the query:
'email' => 'unique:users,email_address,NULL,id,account_id,1'
In the rule above, only rows with an
account_id
of1
would be included in the unique check.
Unfortunately you will have to concatenate a variable value if you want it passed as part of the conditions:
'circle_id' => 'required|unique:donations,circle_id,NULL,id,cause_id,'.$causeId,
Or you make it more readable by specifying validation rules as an array:
'circle_id' => [
'required',
'unique:donations,circle_id,NULL,id,cause_id,'.$causeId,
],