Get reactions of the Reacterable model on concrete Reactable model #239
Answered
by
antonkomarev
antonkomarev
asked this question in
Choose solution
-
Feature request appeared in issue: Right now we have no possibility to get reactions of the Reacterable model on concrete Reactable model using high-level API. We still can do it using low-level API: $reacter = $user->getLoveReacter();
$reactant = $post->getLoveReactant();
$userReactionsOnPost = $reactant->reactions()->where('reacter_id', $reacter->getId())->get(); |
Beta Was this translation helpful? Give feedback.
Answered by
antonkomarev
Apr 2, 2023
Replies: 2 comments 1 reply
-
Solution №1Add new method to the ReactantFacade. public function getReactionsBy(
Reacterable $reacterable,
): iterable; // Get all reactions the post received (already existing method)
$allReactionsOnPost = $post->viaLoveReactant()->getReactions();
// Get reactions the post received from the user
$userReactionsOnPost = $post->viaLoveReactant()->getReactionsBy($user); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
antonkomarev
-
Solution №2Modify current method signature in the ReactantFacade: public function getReactions(): iterable; To the new one: public function getReactions(
Reacterable | null $reacterable = null,
): iterable; // Get all reactions the post received
$allReactionsOnPost = $post->viaLoveReactant()->getReactions();
// Get reactions the post received from the user
$userReactionsOnPost = $post->viaLoveReactant()->getReactions($user); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution №1
Add new method to the ReactantFacade.