>我有2个模型:用户和团队。 - 用户属于团队。 - 一个团队有很多用户。
这是我User
模型。
<?php
namespace App;
use IlluminateNotificationsNotifiable;
use IlluminateContractsAuthMustVerifyEmail;
use IlluminateFoundationAuthUser 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);
}
}
当我尝试使用protected $with = ['team'];
在用户模型中快速加载team
时,它最终出现错误
Maximum function nesting level of '512' reached, aborting!
谁能帮我?谢谢!
把下面放在我的php.ini
对我有用。
基本上你需要增加嵌套级别。
xdebug.max_nesting_level = 1024