From 07bc2fd742873996dfbb27ff5fb7101c717e83ff Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 14 Jun 2022 16:11:43 -0700 Subject: [PATCH] Added maintenance scope for ordering by supplier Signed-off-by: snipe --- app/Models/AssetMaintenance.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Models/AssetMaintenance.php b/app/Models/AssetMaintenance.php index 27273eefc4..3f2c43ad61 100644 --- a/app/Models/AssetMaintenance.php +++ b/app/Models/AssetMaintenance.php @@ -162,6 +162,20 @@ class AssetMaintenance extends Model implements ICompanyableChild * ----------------------------------------------- **/ + /** + * Query builder scope to order on a supplier + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param string $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderBySupplier($query, $order) + { + return $query->leftJoin('suppliers as suppliers_maintenances', 'asset_maintenances.supplier_id', '=', 'suppliers_maintenances.id') + ->orderBy('suppliers_maintenances.name', $order); + } + /** * Query builder scope to order on admin user *