| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
-
- namespace App\Http\Controllers\Api;
-
- use App\Http\Controllers\Controller;
- use App\Http\Requests\RegistEPaperRequest;
- use App\Models\Banner;
- use App\Models\EpaperSubscription;
- use App\Models\HomepageToTop;
- use App\Models\News;
- use App\Models\Setting;
- use App\Supports\Response;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
-
- /**
- * @group Lottery Prize
- */
- class HomePageController extends Controller
- {
- public function __construct(
- )
- {
- }
- public function banners($locale = 'tw')
- {
- $locale = $locale == "tw" ? "zh_TW" : $locale;
- $result = [];
- $banners = Banner::where("visible", true)->get()->map(function ($record) use ($result, $locale){
- $result[] = [
- "imgUrl" => $record->imgUrlLink,
- "mobileImgUrl" => $record->mobileImgLink,
- "title" => $record->getTranslation("title", $locale),
- "content" => $record->getTranslation("content", $locale),
- ];
- });
- }
-
- public function list($locale = 'tw')
- {
- $locale = $locale == "tw" ? "zh_TW" : $locale;
- $result = [];
-
- $webNews = News::where("visible", 1)->orderByDesc("post_date")->limit(3)->get();
- foreach($webNews as $item){
- $result["list"][] = [
- "id" => $item->id,
- "categoryId" => $item->newsCategory->id,
- "category" => $item->newsCategory->getTranslation("name", $locale),
- "postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
- "title" => $item->getTranslation("title", $locale),
- ];
- }
- return Response::ok($result);
- }
- }
|