From 7e499faaca88060bf486b8030eef59ba422e671b Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Fri, 12 Aug 2022 15:25:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=93=81=E7=89=8C=E6=8C=89=E7=85=A7=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=97=B6=E9=97=B4=E5=80=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Admin/Http/Controllers/BrandController.php | 15 ++++++++++++++- beike/Repositories/BrandRepo.php | 7 ++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/beike/Admin/Http/Controllers/BrandController.php b/beike/Admin/Http/Controllers/BrandController.php index 85eb1c83..21dbb897 100644 --- a/beike/Admin/Http/Controllers/BrandController.php +++ b/beike/Admin/Http/Controllers/BrandController.php @@ -6,6 +6,7 @@ * @Date 2022-08-02 19:19:52 * @LastEditTime 2022-08-10 19:07:07 */ + /** * BrandController.php * @@ -24,6 +25,11 @@ use Illuminate\Http\Request; class BrandController extends Controller { + /** + * 显示品牌列表 + * @param Request $request + * @return mixed + */ public function index(Request $request) { $brands = BrandRepo::list($request->only('name', 'first', 'status')); @@ -38,6 +44,13 @@ class BrandController extends Controller return view('admin::pages.brands.index', $data); } + + /** + * 创建品牌 + * + * @param Request $request + * @return array + */ public function store(Request $request): array { $brand = BrandRepo::create($request->all()); @@ -85,7 +98,7 @@ class BrandController extends Controller */ public function getNames(Request $request): array { - $ids = explode(',',$request->get('ids')); + $ids = explode(',', $request->get('ids')); $name = BrandRepo::getNames($ids); return json_success('获取成功', $name); diff --git a/beike/Repositories/BrandRepo.php b/beike/Repositories/BrandRepo.php index 4eab90a0..8fb4ab5a 100644 --- a/beike/Repositories/BrandRepo.php +++ b/beike/Repositories/BrandRepo.php @@ -88,6 +88,7 @@ class BrandRepo if (isset($data['status'])) { $builder->where('status', $data['status']); } + $builder->orderByDesc('created_at'); return $builder->paginate(10)->withQueryString(); } @@ -109,9 +110,9 @@ class BrandRepo $builder = Brand::query() ->where('name', 'like', "$name%") ->select('id', 'name', 'status'); - if ($onlyActive) { - $builder->where('status', 1); - } + if ($onlyActive) { + $builder->where('status', 1); + } return $builder->limit(10)->get(); }