Skip to content
Advertisement

How to append or attach a pivot relationship to a model?

I am trying to get the practice area record of lawyers from practice_areas table along side each time I get a lawyer’s record from lawyer_profiles_table. This two tables (practice_areas and lawyer_profiles) are related with a pivot table named (lawyer_practice_area)

This code below are from the LawyerProfile Model

JavaScript

I tried getting it through an attribute by doing the below

JavaScript

and then appended it this way

JavaScript

but I keep getting this result on postman – “withtimestamps”:”false”

See output below:-

JavaScript

Advertisement

Answer

Probably what you want to use is Eager loading.

Take a look at the documentation.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement