0

How can you combine two collections, one being the collection of parent items together combined with your collection of child items?

I would like something like using the method with and belongsToMany,but in this scenario I cannot use both methods correctly because one table is in another schema and the pivot table is in another schema.

            Area::with('permissoes')
            ->where('sistema', '<>', 'S')
            ->get()

colletion relationship

Magno Alberto
  • 628
  • 14
  • 27

1 Answers1

0

Most Eloquent eagerloads are done with separate queries that just use an IN statement on keys from the previous one. Pivot tables are the exception. It sounds like you need to explicitly tell the Model relation what database your pivot table is in. See my answer here: belongsToMany relationship in Laravel across multiple databases

kmuenkel
  • 2,659
  • 1
  • 19
  • 20
  • Thanks Claymore!!! I had previously read your comment, and his post that helped get close to what I needed. – Magno Alberto Jan 08 '19 at 20:00
  • This child model (permission), I successfully query the table with Eloquent that is in the other schema, because in this model I use a simple class to configure the connection... but even with its hint, the "nested" query only returns parent items. In the result the attribute 'relations' with the 'permission' collection is presented, but without values. – Magno Alberto Jan 08 '19 at 20:10
  • I ended up opting to do everything at hand. Basically, I first consult the parent table to collect the ids, then through the query builder, I consult the pivot table and join with the parent table of the other schema and finally everything with a foreach. – Magno Alberto Jan 08 '19 at 23:23