Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anonymouse703's avatar

what is the proper way on how to make relationship between session table and user table?

I tried to make relation between my user table and session table to list the users in my view and i got this kind of error.

Undefined property: stdClass::$parent_user (View: C:\Users\user\Desktop\iaccs-admin-console\resources\views\pages\admin\system\connection-monitoring\index.blade.php)

here the my view.

@foreach($conn as $user_con) {{$user_con->id}} {{$user_con->parent_user->username}} {{$user_con->parent_user->last_name}},{{$user_con->parent_user->first_name}},{{$user_con->parent_user->last_name}} {{$user_con->parent_user->ip_address}} {{$user_con->parent_user->last_name}} {{$user_con->parent_user->license}} Close @endforeach

and my relations..

in my Session model.

public function child_session(){ return $this->hasMany('App\Session', 'user_id','id'); }

in my User model.

public function parent_user(){ return $this->belongsTo('App\User','user_id','id'); }

0 likes
1 reply

Please or to participate in this conversation.