class Direction extends Model
{
protected $table = 'direction';
protected $fillable = ['id_user', 'name'];
public function executes()
{
return $this->belongsToMany('Growth\Execute', 'execute_direction');
}
}
$arr = [];
$directions = Direction::where('id_user', Auth::user()->id)->get();
foreach ($directions as $value){
$execute = Direction::find($value->id)->executes()->get();
foreach ($execute as $key => $item){
$arr[$value->id]['name'] = $value->name;
$arr[$value->id]['execute'][$item->id]['name'] = $item->name;
$arr[$value->id]['execute'][$item->id]['last_name'] = $item->name;
}
}