达到最大功能嵌套级别'512',正在中止[重复]

问题描述 投票:0回答:1

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

这是我的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!

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

php laravel eloquent eager-loading
1个回答
-1
投票

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

xdebug.max_nesting_level = 1024
© www.soinside.com 2019 - 2024. All rights reserved.