cybercog / laravel-love

Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react?
https://komarev.com/sources/laravel-love
MIT License
1.17k stars 71 forks source link

Get Reacterable for soft deleted (trashed) users #238

Closed schwemmer closed 1 year ago

schwemmer commented 1 year ago

We have a bunch of soft deleted users and would like to still count their reactions (shown as "Deleted User"). The easiest way to do this is to change the relationship in the Reacter Model from this:

public function reacterable(): MorphTo
{
        return $this->morphTo('reacterable', 'type', 'id', 'love_reacter_id');
}

to this:

public function reacterable(): MorphTo
{
        return $this->morphTo('reacterable', 'type', 'id', 'love_reacter_id')->withTrashed();
}

However, the class is final and can not be extended. It would be great if we could somehow pass a parameter to also get reactions from soft deleted users in a future release.

See also #189

antonkomarev commented 1 year ago

Can you call withTrashed like in issue you provided?

$item->getReacter()->reacterable()->withTrashed()->first()
antonkomarev commented 1 year ago

@schwemmer another one way to do this:

  1. Copy \Cog\Laravel\Love\Reacter\Models\Reacter model to your app namespace
  2. Modify reacterable method to fit your needs
  3. Override loveReacter method in your User (Reacterable) model (it should return custom Reacter model)
schwemmer commented 1 year ago

Thanks a lot @antonkomarev, the first way you mentioned above actually works great!

antonkomarev commented 1 year ago

Can we close an issue?

schwemmer commented 1 year ago

Yes, thank you!