I have a many-to-many relationship between my articles and tags table, and want to require the user to input tags in the create/edit article form. I am using Ardent for my validation and have the following in my article model:
class Article extends Ardent {
use PresentableTrait;
protected $presenter = 'presenters\ArticlePresenter';
protected $fillable = ['category_id', 'title', 'description', 'content', 'published'];
public static $rules = array(
'title' => 'required',
'description' => 'required',
'content' => 'required|min:250',
'category_id' => 'exists:categories,id',
'tags' => 'required'
);
public function tags()
{
return $this->belongsToMany('Tag', 'article_tag', 'article_id', 'tag_id');
}
}
My form input:
<div class="form-group @if ($errors->has('tags')) has-error @endif">
{{ Form::label('tags', 'Tags') }}
@if(!isset($article))
{{ Form::text('tags', null, array('class' => 'form-control')) }}
@else
{{ Form::text('tags', $article->present()->implodeTags, array('class' => 'form-control')) }}
@endif
@if ($errors->has('tags')) <p class="help-block">{{ $errors->first('tags') }}</p> @endif
</div>
But the validation fails even if I enter something in the tags field, why is that?