DEV Community

Morcos Gad
Morcos Gad

Posted on • Updated on

Calling some fields from a specific table in a more organized way - Laravel

If you want to call some fields from a specific table in a more organized way, you can write this function in Model :-

public function scopeDoctorFields($query)
{
  $query->select('name');
}
Enter fullscreen mode Exit fullscreen mode

then call function inside Controller :-

$doctors = User::doctorFields()->paginate(100);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)