laravel - How do I add an array of pivot table data to a user? -


i have pivot table of user_activities. have relationship defined in model, example:

$activities = user::find($id)->activities; 

this returns array of objects. want send user object activities array.

i've tried dynamically assigning activities array user object empty object result ($user->activities = {}) instead of array full of activity objects. how add array of activity objects user object?

you may try following approach (your approach should work, related models loaded later on call (dynamically) better, known eager loading):

$user = user::with('activities')->find($id); 

make sure have declared relationship , have related models well.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -