Giter Site home page Giter Site logo

tags's Introduction

Tags

Build Status Software License Latest Version on Packagist Total Downloads

A Tagging package that easily allows you to add tags to your Eloquent models.

An open source package by Cartalyst, code well, rock on!

Version Matrix

Version Laravel PHP Version
14.x 11.x >= 8.2
13.x 10.x >= 8.1
12.x 9.x >= 8.0
11.x 8.x >= 7.3
10.x 7.x >= 7.2.5
9.x 6.x >= 7.2
8.x 5.8.x >= 7.1.3
7.x 5.7.x >= 7.1.3
6.x 5.6.x >= 7.1.3
5.x 5.5.x >= 7.0
4.x 5.4.x >= 5.6.4
3.x 5.3.x >= 5.6.4
2.x 5.1 - 5.2 >= 5.5.9
1.x 4.1 - 5.0 >= 5.4.0

Documentation

Reader-friendly documentation can be found here.

Using the package, but you're stuck? Found a bug? Have a question or suggestion for improving this package? Feel free to create an issue on GitHub, we'll try to address it as soon as possible.

Contributing

Thank you for your interest, here are some of the many ways to contribute.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

This software is released under the BSD 3-Clause License.

tags's People

Contributors

brunogaspar avatar geekpivot avatar grahamcampbell avatar mmic-bjohnson avatar suwardany avatar tabuna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tags's Issues

laravel 5.3.6 composer require got errors

my laravel version is 5.3.6 and get this error
previous 5.2.* is working

$ composer require cartalyst/tags
Using version ^2.1 for cartalyst/tags
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove laravel/framework v5.3.6
    - Conclusion: don't install laravel/framework v5.3.6
    - cartalyst/tags v2.1.0 requires illuminate/database 5.1.*|5.2.* -> satisfiable by illuminate/database[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7].
    - cartalyst/tags v2.1.1 requires illuminate/database 5.1.*|5.2.* -> satisfiable by illuminate/database[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7].
    - don't install illuminate/database v5.1.1|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.13|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.16|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.2|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.20|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.22|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.25|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.28|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.30|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.31|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.41|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.6|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.1.8|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.0|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.19|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.21|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.24|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.25|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.26|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.27|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.28|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.31|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.32|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.37|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.43|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.45|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.6|don't install laravel/framework v5.3.6
    - don't install illuminate/database v5.2.7|don't install laravel/framework v5.3.6
    - Installation request for laravel/framework (locked at v5.3.6, required as 5.3.*) -> satisfiable by laravel/framework[v5.3.6].
    - Installation request for cartalyst/tags ^2.1 -> satisfiable by cartalyst/tags[v2.1.0, v2.1.1].


Installation failed, reverting ./composer.json to its original content.

Please improve documentation about matching tag based on slug when calling WithTag()

Hi!

I've struggled a bit when I tried to find some articles I had tagged with multiple words. I've been figuring out for an hour an a half why if in database everything was set correctly, the related entities were empty. Finally I found that last parameter on scopeWithTag has a type parameter, where you can choose if you want the search based by slug or name. I was calling withTag using tag name but not slug, hence the empty results when I had a tag composed of multiple words (a phrase).

Could you please improve the documentation specifying tags can be matched by slug or name? It will save some time for other people.

The typing added to setSlugGenerator now prevents it from accepting a closure.

Your Environment

  • OS and Version: Mac Catalina
  • PHP Version: 7.2
  • Tags Version: 9.0.*

Expected behaviour

setSlugGenerator is documented to accept a closure as an argument. We were using it like this until the latest upgrade to Laravel 6.x and Tags 9.0.

Actual behaviour

setSlugGenerator now requires a string and therefor no longer accepts a closure. We have since updated our code to comply with this, but your docs will need updating if this was your intention.

Steps to reproduce

If your issue requires any specific steps to reproduce, please outline them here.

Undefined constant 'Cartalyst\Tags\TagsServiceProvider

Hi I am getting the issue

"In app.php line 150
Undefined constant 'Cartalyst\Tags\TagsServiceProvider"
while I am trying to

php artisan serve
command after following all the steps for install and configure cartalyst/tags package.
anybody can help resolving this issue?

thanks
aman ullah

Cannot create tags

Anytime I try to add tags to a model I get SQL error that 'count' has no default value. Since firstOrCreate calls save on the model, and since the count hasn't been provided it obviously fails. The provided migration either needs to set the count field to nullable or provide a default value.

What would be the best approach to heirarchical tagging

Seems tags just be associated to tags, but just wanted to see if I was missing something.

For example

Foo
--bar
--baz

$tag = Tag::find(1) //foo
$tag->setTags('bar', 'baz');

// Get the entity object
$product = Product::find(1);

// Through a string
$product->setTags('bar');

Not truly heirarchical but help me to know what tags are in Foo and if needed find products under Foo by getting all Foo tags and then products with one of those tags.

Thanks
Al

Adding/removing multiple tags is very inefficient

A quick look into the way tags are added and removed proves to be very inefficient

    public function tag($tags): bool
    {
        foreach ($this->prepareTags($tags) as $tag) {
            $this->addTag($tag);
        }

        return true;
    }
    
    /**
     * {@inheritdoc}
     */
    public function addTag(string $name): void
    {
        $tag = $this->createTagsModel()->firstOrNew([
            'slug'      => $this->generateTagSlug($name),
            'namespace' => $this->getEntityClassName(),
        ]);

        if (! $tag->exists) {
            $tag->name = $name;

            $tag->save();
        }

        if (! $this->tags()->get()->contains($tag->id)) {
            $tag->update(['count' => $tag->count + 1]);

            $this->tags()->attach($tag);
        }

        $this->load('tags');
    }
    
    /**
     * {@inheritdoc}
     */
    public function removeTag(string $name): void
    {
        $slug = $this->generateTagSlug($name);

        $namespace = $this->getEntityClassName();

        $tag = $this
            ->createTagsModel()
            ->whereNamespace($namespace)
            ->where(function ($query) use ($name, $slug) {
                $query
                    ->orWhere('name', '=', $name)
                    ->orWhere('slug', '=', $slug)
                ;
            })
            ->first()
        ;

        if ($tag && $this->tags()->get()->contains($tag->id)) {
            $tag->update(['count' => $tag->count - 1]);

            $this->tags()->detach($tag);
        }

        $this->load('tags');
    }

As we can see we have a loop in which a lot of queries are produced $this->tags()->get()and $this->load('tags') are called which load all of the tags of the element twice (which can be a real problem if there is a lot of tags) in addition to the creation and count update

This can be upwards of 3 update and 3 select query per addition of one tag (so if you add 5 tags, you have 30 queries)

I think it shouldn't be the job of addTag to load the relation (especially twice on each call), so I would remove $this->load('tags'); and refactor the rest to be more efficient while still solving #26

    public function addTag(string $name): void
    {
        $slug = $this->generateTagSlug($name);

        $namespace = $this->getEntityClassName();

        $tag = $this->createTagsModel()->firstOrCreate([
            'slug'      => $this->generateTagSlug($name),
            'namespace' => $this->getEntityClassName(),
        ],  [
            'count' => 1,
            'name' => $name,
        ]);

        if ($tag->wasRecentlyCreated || !$this->tags()->exists($tag)) {
            if (!$tag->wasRecentlyCreated) {
                $tag->update(['count' => $tag->count + 1]);
            }
            $this->tags()->attach($tag);
            if ($this->relationLoaded('tags')) {
                $this->tags->add($tag);
            }
        }
    }

This would result in only 2 update and 2 select queries in the worst case and 2 insert and 1 select in the best case

Same goes for the removeTag method with a best case of just 1 select and a worst case of 1 select and 2 update

    public function removeTag(string $name): void
    {
        $slug = $this->generateTagSlug($name);

        $namespace = $this->getEntityClassName();

        $tag = $this->tags()
            ->whereNamespace($namespace)
            ->where(function ($query) use ($name, $slug) {
                $query
                    ->orWhere('name', '=', $name)
                    ->orWhere('slug', '=', $slug)
                ;
            })
            ->first()
        ;

        if ($tag->exists) {
            $tag->update(['count' => $tag->count - 1]);
            $this->tags()->detach($tag);

            if ($this->relationLoaded('tags')) {
                foreach($this->tags as $key => $loadedTag) {
                    if ($loadedTag->getKey() === $tag->getKey()) {
                        unset($this->tags[$key]);
                        break;
                    }
                }
            }
        }
    }

This could be even further improved by querying all tags at once outside of the loop, or using laravel's sync method and diffing the tags before and after to update the counts

untag() didsnt work

hi
whant i use : setTag its work only to add tag
but if i try to delete tag its didnt work

if i have a 4 tags and i do update and stay only 3 its didnt delete the tag (with SetTag())

and
// Remove all the tags
$product->untag();

didnt work to

laravel 5.6

Support Laravel 8

Please add support for Laravel 8. By the way, Thank you for the package.

Getting tags does not reflect changes immediately.

This is my code

$article = Article::where('category_id', $category->id)->where('slug', $article)->firstOrFail();
$article->setTags($request->tags);
// $request->tags is equal to "banana,apple,orange" for example
dd($article->tags);

The dump of the tags does not reflect the changes made, but dumping again a few moments later does.

In contrast, this also does not work:

$article = Article::create($request->all());
$article->setTags($request->tags);
dd($article->tags);

I'm using Laravel 5.2, with no caching in place.

index/relation on tagged.tag_id

Why there is no index/relation on tagged.tag_id? I think it would be a huge performance and consistency boost

I think we should add $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade')->onUpdate('cascade');

php 7.1 problem

i try to install but i get that error:

Problem 1
- Installation request for cartalyst/tags 5.0.* -> satisfiable by cartalyst/tags[v5.0.0].
- cartalyst/tags v5.0.0 requires php >=7.0 -> your PHP version (7.1.11) overridden by "config.platform.php" version (5.6.25) does not satisfy that requirement.

what can i do?

How to get the Tag and Tagged models to use timestamps

Looking at the models for IlluminateTag and IlluminateTagged and they both set the $timestamps to false which causes the model to not maintain date values. I was wondering if there is an accepted way to override this value? Id like to have the tags and taggable rows contain the created_at and updated_at fields if possible.

Get all tags sorted by counter

Hi there, thanks for maintaining this great package!

I'm wondering how can I get all tags sorted by count, I'm currently getting the tags like this:

$tags = Song::allTags()->get();

It works, but I'd like to sort the tags by the counter.

Laravel 5.4

Hi. I've just tried updating to L 5.4 and the latest tags package depends on 5.3. Are there plans for a new release?

cartalyst/tags v3.0.0 requires illuminate/database 5.3.*

Thanks

Laravel 5.7 support

Hi there!

Any plans to add Laravel 5.7 support in the upcoming days? That would be awesome!

I can submit a PR, but after checking Laravel 5.7 changelog, it seems like it would only consist of changing 5.6.* to 5.7.* in composer.json.

Thanks!

Cannot remove tagged tag which has name similar to SQL commands

I'm using cartalyst/tags 2.1 on laravel 5.2 to develop e-learning platform for SQL. I tried to tag the SQL commands appear in each SQL query question.

For example.
If the question's answer is SELECT * FROM table WHERE name LIKE 'a%';
I'll tag SELECT, WHERE and LIKE to the question.

And while I'm working on it, some of the tagged tag can't be removed. And I found 2 cases of the responses.

First case, when I submitted the changes, error returned. For example...

  • BETWEEN
  • LIKE
  • NOT LIKE

And other case, when I submitted the changes, the tag wasn't removed and no error returned. For example...

  • REGEXP

I manually fix the TaggableTrait.php file at line 245.

From...

->where(function ($query) use ($name) {
                $query
                    ->Where('name', $name)
                    ->orWhere('slug', $name)
                ;
            })

To...

->whereRaw('(name LIKE ? OR slug LIKE ?)', [$name, $name])

And the problem goes away.

I'm not quite sure this is cartalyst/tags bug or laravel's bug. I found this in your package, so, I decided to tell you first.

Thank you very much.

[Proposal] Tag Relevance

A very useful feature on tagging is relevance. There could be 5 relevance levels (1-5) and a default relevance level could be set to 5. Tag relevance can be used to control the display of any kind of content and also to fine-tune related content and search results.

This feature should be optional.

tag duplicates on Model

Is it possible to prevent a model instance to be tagged multiple times with the same tag ?
Exemple case :

$tags="Test,test,tEst"; $post->setTags($tags)

still untag() didsnt work

hi
i chack but its didnt fix

i have 2 tags in my business and i try to remove them but its still show to me
this is my code:
$business->untag();
dd($business->tags()->get());

and this is my result
image

i can only to put tags but didnt delete them

laravrl 5.6.15

tahnks

Append tags attribute to model

Is it possible to return $this->tags from a model's appended attribute? It only returns an empty object.

class Articles extends Model implements TaggableInterface
{
    use TaggableTrait;
    
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'articles';

    /**
     * The accessors to append to the model's array form.
     *
     * @var array
     */
    protected $appends = ['tags'];

    /**
     * Get the resource's tags.
     *
     * @param  string  $value
     * @return string
     */
    public function getTagsAttribute()
    {
        return $this->tags();
    }    
}

Change illuminate/database requirement

In composer you are requiring:

"illuminate/database": "5.1.*|5.2.*"

With that, it's not possible to use Laravel 5.3. Can this not be changed to:

"illuminate/database": ">= 5.1",

allTags() does not return anything

When using allTags in Laravel for a model, there are no results returned.
ex Model::allTags()

A quick fix for this was for me to alter TaggableTrait allTags() with this:

return DB::table('tags')->where('namespace', $instance->getEntityClassName())->where('count','>','0')->get();

namespace is necessary?

In the TaggableTraint I find the realationship is morphToMany ,but in the tags table has column namespace,if use this,we just can use

$this->belongsToMany(static::$tagsModel, 'taggable', 'tagged', 'taggable_id', 'tag_id') ->where('namespace',static::$entityNamespace);
may be is not complete, why use morphToMany ? just this question. thanks

Matching a tag based on slug can have side-effects

Hello,

I faced this issue in my project. Let's say a user adds a new tag #Test (or using any other symbol), then in the database we'll have:

slug | name
test | #Test

This looks fine until a user adds a tag Test. Then it'll match with the slug test that already exists, so the count will be 2 and return #Test as a name.

I'm not sure it can be fixed using the current package structure, except for cleaning up the name before adding it or returning the slug as the tag name to the user.

If you have any better ideas how to fix that, please share.

Creating a tag error on pgsql

Having problem with creating a tag on pgsql, mysql is fine. Failing due to violation of not-null constraint on "count" column.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.