/** * 添加标签 * 开放权限 * @method POST_infoAction * @param integer $id [description] * @author NewFuture */ public function POST_infoAction($id = 0) { $uid = $this->auth(); if (Input::post('sid', $sid, 'int') && TagModel::where('id', $id)->inc('count')) { $Hastag = new Model('hastag'); $hastag = ['tag_id' => $id, 'sha_id' => $sid]; try { $Hastag->insert($hastag); $this->response(1, '添加成功'); } catch (Exception $e) { TagModel::where('id', $id)->inc('count', '-1'); $this->response(0, '添加出错'); } } else { $this->response(0, '分享或者标签有误'); } }
public static function withTag($tagName, $type = 'default', $query = null) { $class = get_called_class(); $class = new $class(); $class = $class->getMorphClass(); $tags = TagModel::where('taggable_type', '=', $class)->where('name', '=', $tagName); if ($type) { $tags = $tags->where('type', '=', $type); } $tags = $tags->get(); $results = []; foreach ($tags as $one) { $results[] = $one->taggable_id; } if (is_null($query)) { $query = static::where('id', '!=', '-1'); } if (empty($results)) { return $query->where('id', '=', '-1'); } return $query->whereIn('id', $results); }