I'm working on a ERP using laravel 5.2
I need to do this:
When the user tries to create a new bank, the program will perform a validation to check that the given business name and the given ABI code are unique. When the validation will be executed, the program will ignore all those records with value of 1 on deleted column, for both business name and ABI.
The problem is that it's completely ignoring my where clause.
This is the validation rule:
'business_name' => 'required|max:255|unique:banks,deleted,0',
'abi' => 'required|max:5|min:5|unique:banks,deleted,0'
What you pass as a third parameter is the primary key's value, hence as you don't pass a fourth parameter which identifies the key, it searches for a record with
id, by default, that has a value of
So, you need to pass a fourth parameter, this way, it will ignore all the rows with deleted properties that have the value of
$this->validate($request, [ 'business_name' => 'required|max:255|unique:banks,business_name,1,deleted', 'abi' => 'required|max:5|min:5|unique:banks,abi,1,deleted' ]);