php - Laravel - Multiple query function to multiple eager loaded relationships -


i'm wondering if there's solution multiple closure loading 2 hasone relationships. 1 relationship (personaldata) needed columns, , second relationship (userfile) having clause. works if either remove select personaldata or remove clause userfile, otherwise having 2 closures renders 1 of them null value.

 $user = users::with(['personaldata' => function($a) {                     $a->select('first_name', 'title_name', 'last_name', 'street_address', 'city', 'state', 'country_code', 'zip_code', 'telephone_data', 'skype', 'per_street_address', 'per_city', 'per_state', 'per_country_code', 'per_zip_code');                 },                 'userfile' => function($b) {                     $b->where('type', '1');                 }                 ])                 ->where('user_id', auth::id())                 ->get(); 

change code :

$user = users::with(['personaldata' => function($query) {             $query->select('first_name', 'title_name', 'last_name', 'street_address', 'city', 'state', 'country_code', 'zip_code', 'telephone_data', 'skype', 'per_street_address', 'per_city', 'per_state', 'per_country_code', 'per_zip_code');         }])         ->with(['userfile' => function($query) {             $query->where('type', '1');         }])         ->where('user_id', auth::id())         ->get(); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -