Skip to content
Advertisement

Laravel is_follower and is_following implementation like with Instagram

In Instagram we can know am i followed account and is this account followed me and in Laravel i created a followers migration to implementing that.

JavaScript

here we can attach or detach user_ids to them for example:

JavaScript

now my question is how can i know a user followed me and a user is on my following list

here i have 2 another model as likes and comments which i want to add is_follower and is_following to them

JavaScript

likes output is:

JavaScript

and it should be something like with this output:

JavaScript

how can i implementing this part?

my models:

User

JavaScript

Media:

JavaScript

Likers:

JavaScript

Comments:

JavaScript

Advertisement

Answer

Instead of a Boolean you can accomplish this with the help of withCount() method:

JavaScript

Now,

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement