[英]Laravel : How to use eloquent ORM to find information of NOT authenticated user?
[英]How to get user information in orm relationship?
我的 User.php 模型函數是這樣的
public function send_connection_requests()
{
return $this->hasMany('App\Models\ConnectionRequest','from_user');
}
public function received_connection_requests()
{
return $this->hasMany('App\Models\ConnectionRequest','to_user');
}
我的 coonectionRequest realtionship 是這個->
public function send_connection_requests()
{
return $this->belongsto('App\User','id');
}`
public function received_connection_requests()
{
return $this->belongsto('App\User','id');
}`
`
當我調用函數時
@foreach (Auth::user()->send_connection_requests as $request)
{{request->to_user}}
@endforech
我只獲取包含 from_user 和 to_user id 的連接請求表數據,我需要顯示他們的名字,哪個用戶發送請求和哪個用戶收到請求?
coonectionRequest 關系是belongsTo ,第二個參數是外鍵列名,
而第三列是用戶表中的主列名:
public function send_connection_requests()
{
return $this->belongsto('App\User','from_user','id');
}
public function received_connection_requests()
{
return $this->belongsto('App\User','to_user','id');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.