I have 2 tables: users and users_details
-- users has 3 columns [id,username,password]
-- users_details has [id,user_id,name,address]
I have models for each of them with a relation from users to users_details.
public function details()
{
return $this->hasOne(UserDetails::class, 'user_id', 'id');
}
my question comes here: Is there a way to access UsersDetails attributes as User only.
e.g: {{ $user->name }} : {{ $user->address }} instead of {{ $user->details->name }} : {{ $user->details->address }}
Keep in mind that these tables are only examples and don't have their real range of columns. I need this to implement Laravel/Cashier but this plugin needs 4 new columns in [users] table and I want to put them in [users_details] table.
I haven't tried anything because I don't really know if it is possible. Except for the moment the only workaround that I know of is to make getNameAttribute method in User:
public function getNameAttribute()
{
return $this->details->name;
}