关于模型的一些问题?
userController.php
public function show(User $user)
{
dd($user->replies()->with('topic')->paginate(5));
return view('users.show', compact('user'));
}
问题1: dd($user->replies()->with('topic')->get());这样打印出来,relation关联里怎么就没有内容呢,用paginate就正常;
问题2:dd($user->replies()->with('topic')->paginate(5));我给with('topic')改成with('abcde'),再给下面replies模型里的方法名tipic改成abcde名字,再打印上面的怎么就打印不了了呢,难道方法的名字也有讲究?请教下大家。
models.user.php //用户模型
public function replies(){
return $this->hasMany(Reply::class);
}
models.reply模型里
public function topic(){
return $this->belongsTo(Topic::class);
}
推荐文章: