/** * @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); } }
public function save(Model $model) { $model->save(); if ($model->hasUpdatedTags()) { $model->tags()->sync($model->getUpdatedTagIds()); } if ($model->hasPlacedComment()) { $model->getPlacedComment()->save(); } }
/** * 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; }
/** * 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); }
/** * 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); }
/** * 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); }