Assuming all the users have an official_info reference by default and you want to get all the users who have staffattendance
$usersWithAttendence = Users::with('staffofficial')->whereHas('staffattendance')->whith('staffattendance')->get();
guys iam working with a school project.
i need to insert staff details so what i did is
i had a form which creates an account for staff and then other details in other table
users table below
id
user_name
official_info table
id
staff_id (fk from users table)
designation
here users in parent table and official_ info is child table
now i have another problem
i have an attendance table where columns are
id
staff_id (pk from users table)
att_date
now whats my problem when i display the attendance i need to display the staff_designation also.
for name i did like this
$attendance->staff->user_name (as it is directly connected to user table)
but designation is in official_info table which is a child table then how?
simply to say user is parent table and attendance and official_info are child table. how can i access the official_table info by attendance table??
Kindly some one help please
my user model
public function staffofficial()
{
return $this->hasOne('App\StaffOfficialInfo', 'staff_id');
}
public function staffattendance()
{
return $this->hasmany('App\StaffAttendance', 'staff_id');
}
my staff attendance model
public function staff()
{
return $this->belongsTo('App\User', 'staff_id');
}
my official model
public function user()
{
return $this->belongsTo('App\User', 'staff_id');
}
Please or to participate in this conversation.