本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::tags方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::tags方法的具体用法?PHP Model::tags怎么用?PHP Model::tags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::tags方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attachTags
/**
* @param $model
* @param $tagArray [Input::get('tag') ]
* update the taggables
*/
public function attachTags(Model $model, array $tagArray)
{
// attach related tags
// fetch all tags
$tags = $model->tags;
// fetch all tags in the database assosiated with this event
$attachedTags = $tags->lists('id');
if (!empty($attachedTags)) {
// if there are any tags assosiated with the event
if (empty($tagArray)) {
// if no tags in the GET REQUEST, delete all the tags
foreach ($attachedTags as $tag) {
// delete all the tags
$model->tags()->detach($tag);
}
} else {
// If the used tags is unselected in the GET REQUEST, delete the tags
foreach ($attachedTags as $tag) {
if (!in_array($tag, $tagArray)) {
$model->tags()->detach($tag);
}
}
}
}
// attach the tags
if (!empty($tagArray)) {
$model->tags()->sync($tagArray, true);
}
}
示例2: save
public function save(Model $model)
{
$model->save();
if ($model->hasUpdatedTags()) {
$model->tags()->sync($model->getUpdatedTagIds());
}
if ($model->hasPlacedComment()) {
$model->getPlacedComment()->save();
}
}
示例3: update
/**
* Update a snippet
*
* @param Illuminate\Database\Eloquent\Model $snippet Snippet Model
* @param array $data Array of inputs
* @return boolean
*/
public function update($snippet, array $input)
{
$snippet->fill($input);
if ($snippet->save()) {
if (isset($input['tags'])) {
$snippet->tags()->sync($input['tags']);
} else {
$snippet->tags()->detach();
}
return true;
}
return false;
}
示例4: syncTags
/**
* Sync tags on a model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param array $tagsToSync
*
* @return bool
*/
public function syncTags(Model $model, array $tagsToSync)
{
$tagKeys = Tag::whereIn('name', $tagsToSync)->get()->keyBy('id')->keys()->toArray();
return $model->tags()->sync($tagKeys);
}
示例5: syncTags
/**
* Tagları article'larla senkronize eder
*
* @param \Illuminate\Database\Eloquent\Model $article
* @param array $tags
* @return void
*/
protected function syncTags(Model $article, array $tags)
{
// Mevcut tagları ve oluşturulan yeni tagları
// elde ettikten sonra döndür
$found = $this->tag->findOrCreate($tags);
$tagIds = array();
foreach ($found as $tag) {
$tagIds[] = $tag->id;
}
// Article'a bu tagları ata
$article->tags()->sync($tagIds);
}
示例6: syncTags
/**
* Sync tags for article
*
* @param \Illuminate\Database\Eloquent\Model $article
* @param array $tags
* @return void
*/
protected function syncTags(Model $article, array $tags)
{
// Create or add tags
$found = $this->tag->findOrCreate($tags);
$tagIds = array();
foreach ($found as $tag) {
$tagIds[] = $tag->id;
}
// Assign set tags to article
$article->tags()->sync($tagIds);
}