本文整理匯總了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);
}