Reputation: 161
I am using laravel 5.0 and unique_with feature isnt working properly if i want to ignore a particular row using id field.In my database,the id field is named '_id'.Here's my code:
$test=Request::segment(2);
The $test
retrieves the id from url properly and the name field is validated using following:
'name' => 'Required|Regex:/[a-zA-Z0-9]+\.+[a-zA-Z0-9]+\.+[a-zA-Z0-9]/|Max:100|unique_with:permissions,deleted_at,$test=_id',
But this isn't working.It allows editing/creating even if name is duplicate whereas it should have done just the opposite!! Any suggestions?
Thanks in advance!
Upvotes: 2
Views: 553
Reputation: 111839
I assume you use this validator because there is no unique_with
rule out of the box.
Looking at your code, you should use:
'name' => 'Required|Regex:/[a-zA-Z0-9]+\.+[a-zA-Z0-9]+\.+[a-zA-Z0-9]/|Max:100|unique_with:permissions,deleted_at,' . $test . ' = _id',
because when you use single quotes PHP use string literally without putting there any variables values
Upvotes: 2