Laravel从递归集合

时间:2017-12-15 14:54:20

标签: recursion laravel-5 model laravel-eloquent

在我的用户模型中,我有一个递归函数,它根据我的用户对象构建一个树,它看起来如下所示

    public function children()
    {
        return $this->hasreporters()->with(['children']);
    }

    public function hasreporters() 
    {
        return $this->belongsToMany('App\User', 'reporting_to', 'acc_receiving_from_id', 'acc_reporting_to_id');
    }

比在我的控制器中我得到的数据如下所示

$trees = User::with( 'children')
    ->where('display_off', 0)
    ->where('account_status', 'A')
    ->whereNotIn('ma_status', ['virtuell', 'freelancer'])
    ->where('account_id', 1867)
    ->get();


return response()->json($trees);

我有一个表示为data-uri的头像属性,我想从此查询中删除,我将如何处理?

在这种情况下,forget方法对我不起作用

0 个答案:

没有答案