Hi guys I have here a small code that will load a user status with latest. My question is how can I extend this so that when example user 1 and user 2 are the same department id of 2 they can see there statuses. Just like facebook, when user 1 is friend with user 2, user 1 can see user 2 status and user 2 can also see user 1 status.
$user = Auth::user()->load(['statuses' => function($status)
{
$status->latest();
}]);
TIA :)
Department hasMany Users
, and I assume User hasMany Statuses
, so this will work:
// Department
public function statuses()
{
return $this->hasManyThrough('Status', 'User');
}
// Status
public function user()
{
return $this->belongsTo('User');
}
// User
public function department()
{
return $this->belongsTo('Department');
}
// usage
$statuses = Auth::user()->department->statuses()->with('user')->latest()->get();