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(); }