0
我有3个表:Laravel 4 - 保存标签
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');
}
选择工作,但我想插入到DB
- 如果新的标签 - 插入到
tags
- 插入关系
post_tag
- Incre ASE标签
count
现在我有
$post = new Post;
$post->title = Input::post('title');
$post->body = Input::post('body');
$post->save();
我有,
分开标签。例如javascript, jquery, ajax
。
怎么办?爆炸标签,然后检查每个标签是否存在,然后做2个插入(到tags
和post_tag
)或者是否有“魔术”解决方案?