Skip to content

Instantly share code, notes, and snippets.

@mspivak
Last active December 24, 2015 14:59
Show Gist options
  • Save mspivak/6816621 to your computer and use it in GitHub Desktop.
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.
<?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