mardi 26 janvier 2021

How to get the records of different models with their relationships in a single query?

I make 3 queries, each query with its fields, some are the same, others are different fields, but in the end I want to obtain a single query, that is, to obtain a single arrangement of objects with all records

For which I have done it this way:

$query1 = Model1::query()->select('id','name','insurance_information');
$query2 = Model2::query()->select('id','name','insurance_information');
$query3 = Model3::query()->select('id','name','json_schema');

$query3 = $query3->unionAll($query1) 
          ->unionAll($query2 );

and it effectively brings me all the records of the models, but the problem is that the values ​​of the fields intersect. for example the records of Model1 ($query1) show the property 'json_schema' but 'json_schema' is only for the $query3

The same thing happens with relations, I can't get the relations from each record and ultimately join them into a single array of objects.

How could you perform this functionality



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/39k4hcE
via IFTTT

Aucun commentaire:

Enregistrer un commentaire