golapraj
3 months ago
732
20
Requests

How to retrieve address of all User

Posted 3 months ago by golapraj
//User Model
public function address()
{
        return $this->hasOne('App\Address');
 }

//Address Model
public function user()
{
      return $this->belongsTo('App\User');
}

// I want 
$user=User::all();
$address = $user->address;

error: Property [address] does not exist on this collection instance.

Please sign in or create an account to participate in this conversation.