From b0743389478ea3b92fa1ef75fd4b25d0f563c9bc Mon Sep 17 00:00:00 2001 From: = Date: Fri, 7 May 2021 20:58:24 +1000 Subject: [PATCH] Fixes for statics --- app/Utils/Statics.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/Utils/Statics.php b/app/Utils/Statics.php index 9d5da011f5..5c9a95e9b6 100644 --- a/app/Utils/Statics.php +++ b/app/Utils/Statics.php @@ -12,6 +12,7 @@ namespace App\Utils; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Schema; use Illuminate\Support\Str; /** @@ -69,6 +70,28 @@ class Statics $data = []; foreach (config('ninja.cached_tables') as $name => $class) { + + if (!Cache::has($name)) { + + // check that the table exists in case the migration is pending + if (!Schema::hasTable((new $class())->getTable())) { + continue; + } + if ($name == 'payment_terms') { + $orderBy = 'num_days'; + } elseif ($name == 'fonts') { + $orderBy = 'sort_order'; + } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { + $orderBy = 'name'; + } else { + $orderBy = 'id'; + } + $tableData = $class::orderBy($orderBy)->get(); + if ($tableData->count()) { + Cache::forever($name, $tableData); + } + } + $data[$name] = Cache::get($name); }