hasMany Laravel不工作

时间:2018-03-15 21:51:17

标签: php laravel

$user = User::where('id', $id)->with(['experiences_user'])->first();
        dd($user->experiences_user());

当我执行dd时,它没有显示关系的值。

relations: array:1 [▼
    "experiences_user" => Collection {#196 ▼
      #items: []
    }

用户模型关系:

 public function experiences_user(){
        return $this->hasMany('App\experiences', 'User_id');
    }

经验模型关系:

public function employee(){
    return  $this->belongsTo('App\User','User_id', 'id');
}

1 个答案:

答案 0 :(得分:0)

尝试延迟加载:

# First rename column in visitcounts to `count`:

visitcounts.columns=['count']

# Then merge:
merged_df = pd.merge(df, visitcounts, left_on='id', right_index=True)

>>> merged_df
   index   id  name       dob       visit  count
0      0  111   Joe  1/1/2000    1/1/2018      3
1      1  111   Joe  1/1/2000    1/5/2018      3
4      4  111   Joe  1/1/2000  12/31/2018      3
2      2  122   Bob  1/1/1999    2/8/2018      1
3      3  133  Jill  1/2/1988    7/9/2017      1