我有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!
有人可以帮助我吗?谢谢!
答案 0 :(得分:-2)
在我的php.ini
中添加以下内容对我有用。
基本上,您需要增加嵌套级别。
xdebug.max_nesting_level = 1024