diff --git a/app/Models/Common/Company.php b/app/Models/Common/Company.php index 3bbdcc99d..135e7369b 100644 --- a/app/Models/Common/Company.php +++ b/app/Models/Common/Company.php @@ -442,6 +442,22 @@ class Company extends Eloquent implements Ownable ->select('companies.*'); } + /** + * Sort by company phone + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param $direction + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function phoneSortable($query, $direction) + { + return $query->join('settings', 'companies.id', '=', 'settings.company_id') + ->where('key', 'company.phone') + ->orderBy('value', $direction) + ->select('companies.*'); + } + /** * Sort by company tax number *