1 week ago

Eloquent filtering the many to many relationship on 3rd level

Posted 1 week ago by amitshahc

I have the tables Shops, Enquiries, enquiries_shops, Orders (have enquiry_id, shop_id a foreign key in it)


  • Shops belongsToMany Enquiries.
  • Enquiries belongsToMany Shops.
  • Enquiries hasOne/hasMany Orders. because many shops can buy the same enquiry.

Now I am trying to make appropriate relationship function in the models so that; I can fetch all enquiries belongs to a shop and having the orders entry in the Orders table for that shop, and further filter on enquiry future dates (means not past dates to be fetched.);

I tried passing shopId to the relationship function in Enquiry model. but don't how to further pass it to the Orders table.

Please sign in or create an account to participate in this conversation.