<commit_before><?php namespace Conner\Tagging;

use Illuminate\Support\Facades\Config;
use Illuminate\Database\Eloquent\Collection;

/**
 * Copyright (C) 2014 <NAME>
 */
trait TaggableTrait {

	/**
	 * Boot the soft taggable trait for a model.
	 *
	 * @return void
	 */
	public static function bootTaggableTrait()
	{
		if(static::untagOnDelete()) {
			static::deleting(function($model) {
				$model->untag();
			});
		}
	}
	
	/**
	 * Return collection of tagged rows related to the tagged model
	 *
	 * @return Illuminate\Database\Eloquent\Collection
	 */
	public function tagged()
	{
		return $this->morphMany('Conner\Tagging\Tagged', 'taggable');
	}

	/**
	 * Return collection of tags related to the tagged model
	 * TODO : I'm sure there is a faster way to build this, but
	 * If anyone knows how to do that, me love you long time.
	 *
	 * @return Illuminate\Database\Eloquent\Collection
	 */
	public function getTagsAttribute()
	{
		$tags = new Collection();
		foreach($this->tagged as $tagged) {
			$tags->add($tagged->tag);
		}
		
		return $tags;
	}
	
	/**
	 * Perform the action of tagging the model with the given string
	 *
	 * @param $tagName string or array
	 */
	public function tag($tagNames)
	{
		$tagNames = TaggingUtil::makeTagArray($tagNames);
		
		foreach($tagNames as $tagName) {
			$this->addTag($tagName);
		}
	}
	
	/**
	 * Return array of the tag names related to the current model
	 *
	 * @return array
	 */
	public function tagNames()
	{
		$tagNames = array();
		$tagged = $this->tagged()->get(array('tag_name'));

		foreach($tagged as $tagged) {
			$tagNames[] = $tagged->tag_name;
		}
		
		return $tagNames;
	}

	/**
	 * Return array of the tag slugs related to the current model
	 *
	 * @return array
	 */
	public function tagSlugs()
	{
		$tagSlugs = array();
		$tagged = $this->tagged()->get(array('tag_slug'));

		foreach($tagged as $tagged) {
			$tagSlugs[] = $tagged->tag_slug;
		}
		
		return $tagSlugs;
	}<commit_msg>Allow for eager loading usage on tagNames()<commit_after><?php namespace Conner\Tagging;

use Illuminate\Support\Facades\Config;
use Illuminate\Database\Eloquent\Collection;

/**
 * Copyright (C) 2014 <NAME>
 */
trait TaggableTrait {

	/**
	 * Boot the soft taggable trait for a model.
	 *
	 * @return void
	 */
	public static function bootTaggableTrait()
	{
		if(static::untagOnDelete()) {
			static::deleting(function($model) {
				$model->untag();
			});
		}
	}
	
	/**
	 * Return collection of tagged rows related to the tagged model
	 *
	 * @return Illuminate\Database\Eloquent\Collection
	 */
	public function tagged()
	{
		return $this->morphMany('Conner\Tagging\Tagged', 'taggable');
	}

	/**
	 * Return collection of tags related to the tagged model
	 * TODO : I'm sure there is a faster way to build this, but
	 * If anyone knows how to do that, me love you long time.
	 *
	 * @return Illuminate\Database\Eloquent\Collection
	 */
	public function getTagsAttribute()
	{
		$tags = new Collection();
		foreach($this->tagged as $tagged) {
			$tags->add($tagged->tag);
		}
		
		return $tags;
	}
	
	/**
	 * Perform the action of tagging the model with the given string
	 *
	 * @param $tagName string or array
	 */
	public function tag($tagNames)
	{
		$tagNames = TaggingUtil::makeTagArray($tagNames);
		
		foreach($tagNames as $tagName) {
			$this->addTag($tagName);
		}
	}
	
	/**
	 * Return array of the tag names related to the current model
	 *
	 * @return array
	 */
	public function tagNames()
	{
		$tagNames = array();
		$tagged = $this->tagged()->get(array('tag_name'));

		foreach($tagged as $tagged) {
			$tagNames[] = $tagged->tag_name;
		}
		
		return $tagNames;
	}

	/**
	 * Return array of the tag slugs related to the current model
	 *
	 * @return array
	 */
	public function tagSlugs()
	{
		$tagSlugs = array();
		$tagged = $this->tagged;

		foreach($tagged as $tagged) {
			$tagSlugs[] = $tagged->tag_slug;
		}
		
		return $tagSlugs;
	}
{'fraction_non_alphanumeric': 0.13927291346646187, 'fraction_numerical': 0.002048131080389145, 'mean_word_length': 3.3123620309050774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '731224', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1270, 'n_words': 354}