0

My User.php Model function is this

 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');
 }

and my coonectionRequest realtionship is this->

public function send_connection_requests()
{
   return $this->belongsto('App\User','id');
}`
 public function received_connection_requests()
 {
   return $this->belongsto('App\User','id');
 }`

`

When I am calling function

@foreach (Auth::user()->send_connection_requests as $request)

   {{request->to_user}}

@endforech

I'm only getting connection request table data which contains from_user and to_user id and i need to show their name which user send request and which user recived request ?

1 Answers1

0

coonectionRequest realtionship is belongsTo, the second parameter is the foreign key column name,

while the third column is the primary column name in the users table:

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');
 }
OMR
  • 11,736
  • 5
  • 20
  • 35