我有2个模型:User和Team。-用户属于团队。-一个小组有很多用户。
这是我的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.ini
中放入以下内容对我有用。基本上,您需要增加嵌套级别。
xdebug.max_nesting_level = 1024