I keep multiple address records belonging to a user. but when i write with dd i can’t access other table’s data.
Following my code:
user Table
id | name | country |
--- -------------- ----------
7 | Mr. Lenny Bins| Belgium
2 | Dalton Miller | Swaziland
address Table
user_id | address
-------- ---------
7 | 740 Brown Greens Suite
7 | 9906 Cleora Wall Apt.
2 | 53977 Kip Center Apt
UserModel
public function getAddress()
{
return $this->hasMany(Address::class);
}
UserController
$users = User::where('id' ,7)->with('getAddress')->get();
dd($users->toArray());
// The output of this is below
dd($users->getAddress->toArray());
I get an error when I try like this.
Property [getAddress] does not exist on this collection instance.
