我有3张桌子:
posts
=> id
,title
,body
,... tags
=> id
,name
,count
post_tag
=> post_id
,tag_id
Post
模型已
public function tags() {
return $this->belongsToMany('Tag');
}
Tag
模型已
public function posts() {
return $this->belongsToMany('Post');
}
选择正在运行,但我想插入数据库
tags
post_tag
count
现在我有
$post = new Post;
$post->title = Input::post('title');
$post->body = Input::post('body');
$post->save();
我将标签与,
分开。例如javascript, jquery, ajax
。
怎么做?爆炸标记然后检查每个标记(如果存在),然后执行2次插入(到tags
和post_tag
)或是否有“魔法”解决方案?