Laravel BelongsToMany

3

I have a user table that makes relationship with profile belongsTo , and the profile makes relationship with items from area belongsToMany , and items from area makes relationship with area belongsTo , it is bringing my item from area, but I would like to bring my area in the data, could anyone tell me how I can do this?

I am making the call as follows

Auth::user()->profiles->areasItens->toArray();
    
asked by anonymous 09.12.2014 / 17:58

2 answers

2

Use your User model for example:

$user = User::with(['profiles.areasItens'])
         ->findOrFail(Auth::user()->id);

print_r($user->toArray());
    
17.11.2015 / 20:58
1

I believe that with solves your problem:

Auth::user()->with("profiles", 
     "profiles.areaItens", 
     "profiles.areaItens.area")
     ->profiles->areaItens->toArray();
    
19.01.2015 / 01:22