本文整理汇总了PHP中app\Tag::whereId方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::whereId方法的具体用法?PHP Tag::whereId怎么用?PHP Tag::whereId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Tag
的用法示例。
在下文中一共展示了Tag::whereId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: syncTags
public function syncTags(Article $article, $tags = array(), $isNew = false)
{
$tagall = Tag::all()->toArray();
$newTagIds = $updateTagIds = $existingSlug = $existingTag = [];
if (!empty($tagall)) {
foreach ($tagall as $tag) {
$existingSlug[] = $tag['slug'];
$existingTag[$tag['slug']] = $tag;
}
}
unset($tagall);
if ($tags) {
foreach ($tags as $tag) {
if (!in_array(mb_strtolower($tag, 'UTF-8'), $existingSlug)) {
$name = filter_allowed_words($tag);
$slug = preg_replace('/\\s+/', '-', mb_strtolower($name, 'UTF-8'));
if (in_array($slug, $existingSlug)) {
if ($isNew) {
Tag::whereSlug($slug)->increment('count');
}
$updateTagIds[] = $existingTag[$slug]['id'];
} else {
$firstLetter = getFirstLetter($name);
$newtag = Tag::create(array('name' => $name, 'slug' => $slug, 'letter' => $firstLetter));
$newId = $newtag->id;
$newTagIds[] = $newId;
$updateTagIds[] = $newId;
}
} else {
if ($isNew) {
Tag::whereSlug($tag)->increment('count');
}
$updateTagIds[] = $existingTag[$tag]['id'];
}
}
}
$updateTagIds = array_unique($updateTagIds);
if (!$isNew) {
$oldTagIds = $article->tags->lists('id')->toArray();
$delTagIds = array_diff($oldTagIds, $updateTagIds);
$addTagIds = array_diff($updateTagIds, $oldTagIds);
if (!empty($delTagIds)) {
Tag::whereIn('id', $delTagIds)->decrement('count');
}
if (!empty($addTagIds)) {
foreach ($addTagIds as $addId) {
if (!in_array($addId, $newTagIds)) {
Tag::whereId($addId)->increment('count');
}
}
}
}
$article->tags()->sync($updateTagIds);
unset($newTagIds, $updateTagIds, $existingSlug, $existingTag);
}