我的文章和标签表之间存在多对多关系,并且希望要求用户在创建/编辑文章表单中输入标签。我正在使用Ardent进行验证,并且在我的文章模型中有以下内容:
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');
}
}
我的表单输入:
<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>
但是,即使我在标签字段中输入了一些内容,验证也会失败,这是为什么呢?