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

Get Reacterable for soft deleted (trashed) users #238

Closed
schwemmer opened this issue Mar 30, 2023 · 5 comments
Closed

Get Reacterable for soft deleted (trashed) users #238

schwemmer opened this issue Mar 30, 2023 · 5 comments

Comments

@schwemmer
Copy link

schwemmer commented Mar 30, 2023

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

@schwemmer schwemmer changed the title Get Reacterable for soft deleted users Get Reacterable for soft deleted (trashed) users Mar 30, 2023
@antonkomarev
Copy link
Member

Can you call withTrashed like in issue you provided?

$item->getReacter()->reacterable()->withTrashed()->first()

@antonkomarev
Copy link
Member

@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
Copy link
Author

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

@antonkomarev
Copy link
Member

Can we close an issue?

@schwemmer
Copy link
Author

Yes, thank you!

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

No branches or pull requests

2 participants