ardent icon indicating copy to clipboard operation
ardent copied to clipboard

False validation errors when saving model created statically

Open abdouz opened this issue 10 years ago • 1 comments

I have encountered the following issue not sure if its Ardent or Laravel Issue

  • define a model with Ardent validation rules normally with some field being unique.
class Page Extends \Ardent {
    protected $table = 'pages';
    public static $rules = array(
        'title' => array('required', 'min:8', 'unique:pages')
  • try to create model(s) from such definition in the controller fails if using static create and succeeds if using new & fill.
$page = Page::create(array('title' => 'blah blah'));
$page->save()

sends a validation error which is not true

$page = new Page
$page->fill(array('title'=>'blah blah'));

works fine and doesn't return false errors

could you please help me regarding this?

abdouz avatar Apr 08 '14 08:04 abdouz

Create already actions save so you don't need to. I assume the validation error is that the title already exists?

If you must use the code you have, use update uniques

$page = Page::create(array('title' => 'blah blah'));
$page->updateUniques()

sjdaws avatar May 02 '14 13:05 sjdaws