cviebrock / eloquent-taggable

Easily add the ability to tag your Eloquent models in Laravel.
MIT License
537 stars 72 forks source link

Model::allTags() and related methods fail with Relation::enforceMorphMap() #140

Closed anaxamaxan closed 8 months ago

anaxamaxan commented 8 months ago

Please be sure you include all the relevant information in your issue so we can help you:

Installed per instructions. Using only one model so far, App\Models\Course, which implements Taggable with no overrides.

// AppServiceProvider::boot()
Relation::enforceMorphMap([
    'course' => Course::class,
]);

Using the trait right out of the can:

class Course extends Model implements HasCommentsInterface, HasNotes
{
    use HasFactory,
        HasComments,
        HasNotesTrait,
        SoftDeletes,
        Taggable;
// etc
}

The main issue comes from depending on php get_class() in TagService::getAllTags() and TagService::getPopularTags(). Also the anonymous class in TagService::getQualifiedPivotTableName() needs to either implement the getMorphClass() method from Illuminate\Database\Eloquent\Concerns\HasRelationships or otherwise get around the morph map enforcement.

I'll open a PR for the above.

cviebrock commented 8 months ago

Version 10.0.1 has been tagged with this fix. Thanks again @anaxamaxan !