Reactable Ordering

Setup models

Adding query scopes to Model described in Setup Reactable page.

Usage

Order by Reaction Counter

Add reaction counter aggregate of exact reaction type to reactables

$comments = Comment::query() ->joinReactionCounterOfType('Like') ->get();

joinReactionCounterOfType method adds reaction_like_count & reaction_like_weight virtual attributes to each comment in collection.

Custom counters virtual attributes prefix

Join methods supports chaining and their default virtual attributes prefix reaction_{$type} could be overridden with optional method argument.

$comments = Comment::query() ->joinReactionCounterOfType('Like') ->joinReactionCounterOfType('Dislike', 'hates') ->get();

Then each Comment instance will have reaction_like_count, reaction_like_weight, hates_count, hates_weight virtual attributes.

Order models by reaction counter count value

$comment = Comment::query() ->joinReactionCounterOfType('Like') ->orderBy('reaction_like_count', 'desc') ->get();

Order models by reaction counter weight value

$comments = Comment::query() ->joinReactionCounterOfType('Like') ->orderBy('reaction_like_weight', 'desc') ->get();

Order by Reaction Total

Add reaction total aggregate to reactables

$comments = Comment::query() ->joinReactionTotal() ->get();

Each Reactable model will contain reaction_total_count & reaction_total_weight virtual attributes.

Custom totals virtual attributes prefix

Default virtual attributes prefix is reaction_total, but it could be overridden with optional method argument.

$comments = Comment::query() ->joinReactionTotal('reaction_summary') ->get();

Then each Reactable model will contain reaction_summary_count & reaction_summary_weight virtual attributes.

Order by total count of reactions

$comments = Comment::query() ->joinReactionTotal() ->orderBy('reaction_total_count', 'desc') ->get();

Order by total weight of reactions

$comments = Comment::query() ->joinReactionTotal() ->orderBy('reaction_total_weight', 'desc') ->get();