I decided to revise and extend relationships in v6. Initially was planned to do it in v5 but it will require database changes and Laravel 5.6 morphTo implementation.
There is a need to fetch:
- Likeables of the Liker.
- Likers of the Likeable.
- (?) Likes which were added to Likeables.
- (?) Likes which were added by Liker.
I'm not 100% sure about points 3 & 4. Do we really need to get those likes? Need to write use cases for them.
Old implementation
Only 3rd point is implemented right now.
php
// Likes and dislikes related to Likeable
$likesAndDislikes = $article->likesAndDislikes();
// Likes related to Likeable
$likes = $article->likes();
// Dislikes related to Likeable
$dislikes = $article->dislikes();
该提问来源于开源项目:cybercog/laravel-love