Skip to content

Commit

Permalink
[5.3] Illuminate\Validation\Rules\Unique bug fix (#16948)
Browse files Browse the repository at this point in the history
* Illuminate\Validation\Rules\Unique fix

* Style update

* Better if statement

* Fix the test

* Test completion
  • Loading branch information
MrAtiebatie authored and taylorotwell committed Dec 26, 2016
1 parent 5e1e5fe commit 45d8718
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Rules/Unique.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function __toString()
return rtrim(sprintf('unique:%s,%s,%s,%s,%s',
$this->table,
$this->column,
$this->ignore ?: 'NULL',
$this->ignore ? '"'.$this->ignore.'"' : 'NULL',
$this->idColumn,
$this->formatWheres()
), ',');
Expand Down
9 changes: 7 additions & 2 deletions tests/Validation/ValidationUniqueRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$this->assertEquals('unique:table,NULL,NULL,id,foo,bar', (string) $rule);

$rule = new Illuminate\Validation\Rules\Unique('table', 'column');
$rule->ignore(1, 'id_column');
$rule->ignore('Taylor, Otwell', 'id_column');
$rule->where('foo', 'bar');
$this->assertEquals('unique:table,column,1,id_column,foo,bar', (string) $rule);
$this->assertEquals('unique:table,column,"Taylor, Otwell",id_column,foo,bar', (string) $rule);

$rule = new Illuminate\Validation\Rules\Unique('table', 'column');
$rule->ignore(null, 'id_column');
$rule->where('foo', 'bar');
$this->assertEquals('unique:table,column,NULL,id_column,foo,bar', (string) $rule);
}
}

0 comments on commit 45d8718

Please sign in to comment.