BookStack\Entity::tags PHP Méthode

tags() public méthode

Get the Tag models that have been user assigned to this entity.
public tags ( ) : Illuminate\Database\Eloquent\Relations\MorphMany
Résultat Illuminate\Database\Eloquent\Relations\MorphMany
    public function tags()
    {
        return $this->morphMany(Tag::class, 'entity')->orderBy('order', 'asc');
    }

Usage Example

Exemple #1
0
 /**
  * Save an array of tags to an entity
  * @param Entity $entity
  * @param array $tags
  * @return array|\Illuminate\Database\Eloquent\Collection
  */
 public function saveTagsToEntity(Entity $entity, $tags = [])
 {
     $entity->tags()->delete();
     $newTags = [];
     foreach ($tags as $tag) {
         if (trim($tag['name']) === '') {
             continue;
         }
         $newTags[] = $this->newInstanceFromInput($tag);
     }
     return $entity->tags()->saveMany($newTags);
 }