From 77055991af36877552e1921466987d3066774d6b Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Wed, 21 Feb 2018 15:15:12 -0600 Subject: [PATCH] Get the correct ordering for flight route on map --- app/Models/Pirep.php | 2 +- app/Repositories/AcarsRepository.php | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index 5f2fc66f..3245ac64 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -240,7 +240,7 @@ class Pirep extends BaseModel { return $this->hasMany(Acars::class, 'pirep_id') ->where('type', AcarsType::FLIGHT_PATH) - ->orderBy('created_at', 'asc'); + ->orderBy('created_at', 'desc'); } public function acars_logs() diff --git a/app/Repositories/AcarsRepository.php b/app/Repositories/AcarsRepository.php index ea22a56a..c3d1a7c4 100644 --- a/app/Repositories/AcarsRepository.php +++ b/app/Repositories/AcarsRepository.php @@ -28,12 +28,18 @@ class AcarsRepository extends BaseRepository //implements CacheableInterface 'type' => $type, ]; - $order_by = 'created_at'; - if($type === AcarsType::ROUTE) { - $order_by = 'order'; + switch($type) { + default: + case AcarsType::FLIGHT_PATH: + case AcarsType::LOG: + $order_by = 'created_at'; + break; + case AcarsType::ROUTE: + $order_by = 'order'; + break; } - return $this->orderBy('order', 'asc')->findWhere($where); + return $this->orderBy($order_by, 'asc')->findWhere($where); } /**