Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model Config not being used properly #172

Closed
DanWithams opened this issue Aug 1, 2019 · 2 comments
Closed

Model Config not being used properly #172

DanWithams opened this issue Aug 1, 2019 · 2 comments
Labels

Comments

@DanWithams
Copy link

DanWithams commented Aug 1, 2019

tagging.php config allows the specification of the following keys;

// Model to use to store the tags in the database
'tag_model' => '...',

...

// Model to use for the relation between tags and tagged records
'tagged_model' => '...',

However these are not used consistently the \Conner\Tagging\Taggable trait which means the Taggable trait is pretty un-useable with custom Models. E.g.

/**
     * Adds a single tag
     *
     * @param string $tagName
     */
    private function addTag($tagName)
    {
        $tagName = trim($tagName);

        if(strlen($tagName) == 0) {
            return;
        }

        $tagSlug = TaggingUtility::normalize($tagName);

        $previousCount = $this->tagged()->where('tag_slug', '=', $tagSlug)->take(1)->count();
        if($previousCount >= 1) { return; }

        $tagged = new Tagged([  // This Model is the shipped-with Model, rather than the custom Model provided via the config file.
            'tag_name' => TaggingUtility::displayize($tagName),
            'tag_slug' => $tagSlug,
        ]);

        $this->tagged()->save($tagged);

        TaggingUtility::incrementCount($tagName, $tagSlug, 1);

        unset($this->relations['tagged']);

        event(new TagAdded($this, $tagSlug, $tagged));
    }

Is this an oversight or am I missing some wider picture? I am happy to make a PR with the changes if someone can let me know that \Conner\Tagging\Taggable should also me making use of the config classnames.

My proposition would be to extend the TaggingUtility to be able to create instances of config provided Models and use them throughout the require places in the Taggable trait in order to accomplish full customisation.

@rtconner rtconner added the bug label Aug 12, 2019
@rtconner
Copy link
Owner

Fixed in v3.2.3

@rtconner
Copy link
Owner

Thank you for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants