当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::tags方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:34,代码来源:TagRepository.php

示例2: save

 public function save(Model $model)
 {
     $model->save();
     if ($model->hasUpdatedTags()) {
         $model->tags()->sync($model->getUpdatedTagIds());
     }
     if ($model->hasPlacedComment()) {
         $model->getPlacedComment()->save();
     }
 }
开发者ID:sdlyhu,项目名称:laravelio,代码行数:10,代码来源:EloquentArticleRepository.php

示例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;
 }
开发者ID:gamerwalt,项目名称:laravelsnippets,代码行数:20,代码来源:EloquentSnippetRepository.php

示例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);
 }
开发者ID:displore,项目名称:tags,代码行数:13,代码来源:Tagger.php

示例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);
 }
开发者ID:marmaray,项目名称:Implementing-Laravel,代码行数:19,代码来源:EloquentArticle.php

示例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);
 }
开发者ID:xenxa,项目名称:Implementing-Laravel,代码行数:18,代码来源:EloquentArticle.php


注:本文中的Illuminate\Database\Eloquent\Model::tags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。