Reactable Ordering
Order by Reaction Counter
Add reaction counter aggregate of exact reaction type to reactables
$reactionType = ReactionType::fromName('Like');
$comments = Comment::query()
->joinReactionCounterOfType($reactionType)
->get();
joinReactionCounterOfType
method adds reactions_count
& reactions_weight
virtual attributes to each comment in collection.
One type of reaction counters could be joined at a time.
Order models by reactions counter count value
$comment = Comment::query()
->joinReactionCounterOfType($reactionType)
->orderBy('reactions_count', 'desc')
->get();
Order models by reactions counter weight value
$comments = Comment::query()
->joinReactionCounterOfType($reactionType)
->orderBy('reactions_weight', 'desc')
->get();
Order by Reaction Total
Add reaction total aggregate to reactables
$comments = Comment::query()
->joinReactionTotal()
->get();
Each Reactable model will contain reactions_total_count
& reactions_total_weight
virtual attributes.
Order by total count of reactions
$comments = Comment::query()
->joinReactionTotal()
->orderBy('reactions_total_count', 'desc')
->get();
Order by total weight of reactions
$comments = Comment::query()
->joinReactionTotal()
->orderBy('reactions_total_weight', 'desc')
->get();
Updated almost 6 years ago