Domanda

I'm having a problem using LaravelBook/Ardent. My logic is exclude the soft deleted rows in unique validation using the code:

public static $rules = array(
    'name'  => 'required|unique:paper_colors,name,deleted_at,NULL',
    'description' => 'required|between:2,255',
    'code' => 'required'
);

But when I run the updateUniques I'm still getting The name has already been taken. and this sql:

select count(*) as aggregate from `paper_colors` where `name` = '4/0' and `id` <> '2'

I'm expecting the sql will be:

select count(*) as aggregate from `paper_colors` where `name` = '4/0' and `id` <> '2' and `deleted_at` is null

Can someone help me to solve this. I'm stuck almost last night on this. Still can't figure it out how to deal with this.

È stato utile?

Soluzione

I found out that Ardent is dropping the Laravel Validation feature: Adding Additional Where Clauses

So my solution to overcome this bug is to add additional code under LaravelBook\Ardent\Ardent@buildUniqueExclusionRules at line: 799, but I didn't do that since I'm depending for their any updates in the future. So I just create a class that extend LaravelBook\Ardent\Ardent and copy buildUniqueExclusionRules and modify it.

if (count($params)>2)
{
    $c = count($uniqueRules);
    for ($i=1; $i < count($params); $i++, $c++) { 
        $uniqueRules = array_add($uniqueRules, $c, $params[$i]);
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top