From f58bb18fe7e9348372d81c11aea7e678834e85b7 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Wed, 31 Aug 2022 11:29:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=81=E7=94=A8=E7=9A=84=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/SettingController.php | 2 +- beike/Repositories/CountryRepo.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/beike/Admin/Http/Controllers/SettingController.php b/beike/Admin/Http/Controllers/SettingController.php index a54c16f2..ecb0eb57 100644 --- a/beike/Admin/Http/Controllers/SettingController.php +++ b/beike/Admin/Http/Controllers/SettingController.php @@ -40,7 +40,7 @@ class SettingController extends Controller ]; $data = [ - 'countries' => CountryRepo::all(), + 'countries' => CountryRepo::listEnabled(), 'currencies' => CurrencyRepo::listEnabled(), 'tax_address' => $tax_address, 'customer_groups' => CustomerGroupDetail::collection(CustomerGroupRepo::list())->jsonSerialize(), diff --git a/beike/Repositories/CountryRepo.php b/beike/Repositories/CountryRepo.php index 9d9e7929..769f431b 100644 --- a/beike/Repositories/CountryRepo.php +++ b/beike/Repositories/CountryRepo.php @@ -13,6 +13,8 @@ namespace Beike\Repositories; use Beike\Models\Country; use Illuminate\Contracts\Pagination\LengthAwarePaginator; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; class CountryRepo { @@ -100,6 +102,21 @@ class CountryRepo return $builder->paginate(20)->withQueryString(); } + + /** + * 获取已启用国家列表 + * @return Builder[]|Collection + */ + public static function listEnabled(): Collection|array + { + return Country::query()->where('status', true)->select('id', 'name')->get(); + } + + + /** + * 获取所有国家列表 + * @return Builder[]|Collection + */ public static function all() { return Country::query()->select('id', 'name')->get();