HomeController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Http\Controllers\Api\Course;
  11. use App\Http\Controllers\Controller;
  12. use App\Http\Resources\CMS\BannerResource;
  13. use App\Repositories\Enums\Base\BannerTypeEnum;
  14. use App\Repositories\Models\Base\Banner;
  15. use App\Repositories\Models\Course\Category;
  16. use App\Repositories\Models\Info\Information;
  17. use App\Repositories\Presenters\Base\BannerPresenter;
  18. use App\Repositories\Presenters\Info\InformationPresenter;
  19. use Illuminate\Support\Facades\Request;
  20. use Jiannei\Response\Laravel\Support\Facades\Response;
  21. class HomeController extends Controller
  22. {
  23. public function index(Request $request)
  24. {
  25. $category = Category::query()->where('parent_id', 0)->status()->select(['id', 'name'])->orderByDesc('sort')->get();
  26. $banners = Banner::query()->status()->active()->where('type', BannerTypeEnum::HOME)->orderBy('sort')->get();
  27. $banners = (new BannerPresenter())->present($banners);
  28. $notice = Information::query()->status()->where('type_id', 1)->orderBy('sort')->orderByDesc('id')->limit(3)->get();
  29. $notice = (new InformationPresenter())->present($notice);
  30. $news = Information::query()->status()->where('type_id', 2)->orderBy('sort')->orderByDesc('id')->limit(4)->get();
  31. $news = (new InformationPresenter())->present($news);
  32. return Response::success(compact('category', 'banners', 'news', 'notice'));
  33. }
  34. }