ardent
ardent copied to clipboard
False validation errors when saving model created statically
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?
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()