You need belongsToMany from both classes because that's a many to many relationship
https://laravel.com/docs/9.x/eloquent-relationships#many-to-many
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm having hard time figuring out the query I need in my scenario. Not sure I can use eloquent alone and I might use raw query.
There are the following tables: lists, items, and the pivot table items_to_lists, which has the columns list_id and items_id
Relationships are set like so - items hasMany items_to_lists and lists belongsToMany items_to_lists
I am given a list id, and I need to get all the items that belong to this list and to the user's account (which is easy to find by Auth::user()->account)
Is it possible to do using eloquent or I will need some use of raw queries? And what would be the more efficient way if there are tens of thousands of items?
Thanks
Please or to participate in this conversation.