Laravel 5 Laravel关系-静态与非静态的不同结果

Laravel 5 Laravel关系-静态与非静态的不同结果,laravel-5,static,relation,non-static,Laravel 5,Static,Relation,Non Static,我遇到了拉威尔的一个问题,这是我一生都无法解决的 我有以下模型,基本上是: class Team extends Model { public function notices() { return $this->belongsToMany('App\Notice', 'notice_recipients'); } } class Notice extends Model { public function teams() {

我遇到了拉威尔的一个问题,这是我一生都无法解决的

我有以下模型,基本上是:

class Team extends Model
{
    public function notices()
    {
        return $this->belongsToMany('App\Notice', 'notice_recipients');
    }
}

class Notice extends Model
{
    public function teams()
    {
        return $this->belongsToMany('App\Team', 'notice_recipients');
    }
}
在我的团队模型中,我遇到了以下问题:

dump($this->notices);
将不同的结果返回给:

dump(Team::find($this->id)->notices);

为了进一步调查,我有以下代码:

    dump($this->id); // = 20
    dump($this->notices()->toSql());
    dump($this->notices()->getBindings());
    dump($this->notices);
    dump(Team::find($this->id)->notices()->toSql());
    dump(Team::find($this->id)->notices()->getBindings());
    dump(Team::find($this->id)->notices);
就我所知,第2-3行的输出与第5-6行完全相同,因此我应该得到相同的结果,但是第4行和第7行输出的结果不同!(第4行似乎只输出第7行输出的结果的一部分)

这个问题似乎只发生在某些团队模型上,而且对于问题是否发生在任何特定模型上,它似乎完全是随机的

关于可能发生的事情或者我如何进一步调试这个问题,有什么想法吗


非常感谢

注意收件人表中是否有以下字段

身份证 团队id 通知单

试试这个也许会有用

    public function notices()
    {
        return $this->belongsToMany('App\Notice', 'notice_recipients', 'team_id', notice_id);
    }

public function teams()
    {
        return $this->belongsToMany('App\Team', 'notice_recipients', 'notice_id', 'team_id');
    }

请注意,如果收件人表包含以下字段

身份证 团队id 通知单

试试这个也许会有用

    public function notices()
    {
        return $this->belongsToMany('App\Notice', 'notice_recipients', 'team_id', notice_id);
    }

public function teams()
    {
        return $this->belongsToMany('App\Team', 'notice_recipients', 'notice_id', 'team_id');
    }