Last active
December 24, 2015 14:59
-
-
Save mspivak/6816621 to your computer and use it in GitHub Desktop.
Workaround to get Ardent's rule "unique" not fail when updating existing records.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Mauro\Ardent; | |
class Ardent extends \LaravelBook\Ardent\Ardent { | |
public function validate( array $rules = array(), array $customMessages = array() ) { | |
if (empty($rules)) { | |
$rules = static::$rules; | |
if ( $this->exists ) { | |
foreach ($rules as $field => $rule) { | |
$rules[$field] = str_replace('{id}', isset($this) ? "{$this->id}" : '', $rule); | |
} | |
} | |
} | |
return parent::validate( $rules, $customMessages ) ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment