示例#1
0
 public static function updateTags($taggable, $newTags)
 {
     $oldTags = $taggable->tags()->lists('tag_id');
     $tagsIn = array_diff($newTags, $oldTags);
     $tagsOut = array_diff($oldTags, $newTags);
     if (!empty($tagsIn)) {
         Tag::whereIn('id', $tagsIn)->increment('menciones');
         $taggable->tags()->attach($tagsIn);
     }
     if (!empty($tagsOut)) {
         Tag::whereIn('id', $tagsOut)->decrement('menciones');
         $taggable->tags()->detach($tagsOut);
     }
 }
示例#2
0
 /**
  * Sync tags.
  * 
  * @param array $tagsToSync
  *
  * @return bool
  */
 public function syncTags(array $tagsToSync)
 {
     $tagKeys = Tag::whereIn('name', $tagsToSync)->get()->keyBy('id')->keys()->toArray();
     return $this->tags()->sync($tagKeys);
 }
 public function bulk_destroy()
 {
     $tagIds = Input::get('Tags');
     Tag::whereIn('id', $tagIds)->delete();
     return Redirect::to('dashboard/tags')->withSuccess(count($tagIds) . ' ' . str_plural('tag', count($tagIds)) . ' destroyed.');
 }
示例#4
0
文件: Tag.php 项目: rituzy/iblog
 public static function getTagByIDs($tm)
 {
     return Tag::whereIn('id', $tm);
 }
 /**
  * @回车站彻底删除
  */
 public function realDelete($ids)
 {
     //检查删除安全和正确性
     $arr = explode(',', $ids);
     //检查删除权限,防止当前用户删除其他用户文章漏洞
     foreach ($arr as $v) {
         if (Article::find($v)->uid != Auth::id()) {
             return Redirect::route('articles.recycle')->with('error', '警告!无法对未授权的文章进行危险操作!');
         }
     }
     //检查删除项必须是没有分类的文章,防止非法get提交
     $record = Article::whereIn("id", $arr)->sum('cid');
     if ($record > 0) {
         return Redirect::route('articles.recycle')->with('error', '警告!检查到有非回车站中的文章进行危险操作!');
     }
     //彻底删除对应tag
     Tag::whereIn('aid', $arr)->delete();
     //彻底删除文章
     Article::destroy($arr);
     //回到回车站主页
     return Redirect::route('articles.recycle')->with('message', '删除成功!');
 }
示例#6
0
 /**
  * 
  * @param type $name
  * @return type
  */
 public static function getTagByName(array $names)
 {
     return Tag::whereIn('name', $names)->get(['id', 'name', 'slug']);
 }
示例#7
0
 public static function getSkillsname($tagIds)
 {
     if (!empty($tagIds)) {
         //$tags = str_split($tagIds);
         $tags = explode(',', $tagIds);
         $skills = Tag::whereIn('tags.id', $tags)->get();
         return $skills;
     } else {
         return false;
     }
 }