Hello. I do not understand how to write a request (eloquent) correctly; I need to get news from all users to whom I am subscribed.

The table follows: id, from_id, to_id

Table users: id, username, email, etc ..

Table shots (news) id, user_id, title, category, etc ..

I just want to get it all in one request, because in Blade, I compare the total amount of news with the limit that I set - and if there is more news, I show the "download more" button, but, I don’t get anything, and I To be honest, I don’t understand what kind of connection I need to use. Help please, or poke into the documentation for the desired connection, I will dig it. thank

I tried this:

return $this->hasManyThrough('App\Shot','App\Follow','from_id','user_id'); 

But as I understood, eloquent does not understand that he needs to find posts with to_id == user_Id, but I do not understand how to tell him that, his brain is already boiling.

    1 answer 1

    For this to work, you need to have an intermediate connection between App\Shot and App\Follow configured, and you’re most likely configured between App\Shot and App\User .
    In general, for good, you need to get rid of the App\Follow model, make a many-to-many connection between User and User and then try to make

     return $this->hasManyThrough('App\Shot','App\User','id','user_id'); 

    PS once answered a similar question, mb here will be clearer https://ru.stackoverflow.com/a/417468/176557