我遇到了一个小问题,我尝试检索我与用户的表地址关系的数据。Laravel关系表用户和地址
在我的数据库地址中,我有一个与用户表ID关联的外键user_id。
我的车型用户
public function addresses()
{
return $this->belongsToMany('Address');
}
我的模型Addresse
public function user(){
return $this->hasOne('User');
}
我尝试在我的UsersController找回我尝试在我的个人资料的方法来显示用户 控制器用户的地址
public function profile($id){
if($id != Auth::user()->id){
return Redirect::to('logout');
}
$user=User::find(Auth::user()->id);
$address = $user->addresse;
dd($address);
$comments = Comment::where('user_id','=',Auth::user()->id)
->take(10)->get();
return View::make('users.profile')
->with(array('comments'=>$comments,'address'=>$address));
}
但在我看来,我无法检索我的相关数据离子用户地址。
profile.blade.php视图
thx其工作很好 – nicolassiuol
很酷,我很高兴它解决了你的问题。如果您能将其标记为正确答案,我将不胜感激。谢谢。 –