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?

Home Page:https://komarev.com/sources/laravel-love

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is Reacted By in Eager Loading

wimil opened this issue · comments

commented

Hi, thank you for such a beautiful package, I have a question. Is there any way to know if reactant has reacted to reacter in an Eager Loading, I have read the documentation but I can't find any way to do it.

example in Eager Loading you can do this:
https://laravel-love.readme.io/docs/eager-loading

loveReactant.reactions.type
loveReactant.reactions.reacter.reacterable
loveReactant.reactionCounters
loveReactant.reactionTotal

I would like something like this:

loveReactant.isReactedBy

I hope you can help me. thanks greetings

In eager loading you should list relationships. Method isReactedBy is not a relation, so Eloquent can not understand what relations should be loaded eagerly.

If you only need to check isReactedBy without N+1 issue - in this case following relationships should be enough:

$comment = Comment::query()
    ->with([
        'loveReactant.reactions.reacter.reacterable',
        'loveReactant.reactions.type',
    ])
    ->get();

@wimil I'm closing this issue. Feel free to continue conversation here if your issue isn't solved yet.