达到最大功能嵌套级别“ 512”,正在中止

时间:2018-10-24 08:11:10

标签: php laravel eloquent eager-loading

我有2个模型: 用户 团队 。     -用户属于团队。     -一个团队有很多用户。

这是我的User模型。

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable {

    use Notifiable, HasRole;

    protected $guarded = [];

    protected $with = ['team', 'role'];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function team()
    {
        return $this->belongsTo(Team::class);
    }
}

Team模型:

class Team extends Model {

    protected $with = ['leader'];

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('membersCount', function ($builder) {
            $builder->withCount('members');
        });
    }

    public function leader()
    {
        return $this->belongsTo(User::class, 'leader_id');
    }

    public function members()
    {
        return $this->hasMany(User::class);
    }
}

当我试图通过使用team在用户模型中加载protected $with = ['team'];时,它以错误结束

Maximum function nesting level of '512' reached, aborting!

有人可以帮助我吗?谢谢!

1 个答案:

答案 0 :(得分:-2)

在我的php.ini中添加以下内容对我有用。
基本上,您需要增加嵌套级别。

xdebug.max_nesting_level = 1024