Level 2
@deepu07 you can use select with hasMany method
public function users()
{
return $this->hasMany(User::class, 'department_id', 'id')->select('id', 'user_name', 'email');
}
//Department Model
public function users()
{
return $this->hasMany(User::class, 'department_id', 'id');
}
in controller doing like this
$department_users = Department::with(['users' => function($query) {
$query->select(['id', 'user_name', 'email']);
}])->get();
somehow I'm getting empty users in results. How can I get selected column values in this case? any help that would be great. Thanks!
Please or to participate in this conversation.