|
|
@@ -22,9 +22,9 @@ class NewsController extends Controller
|
|
22
|
22
|
{
|
|
23
|
23
|
}
|
|
24
|
24
|
|
|
25
|
|
- public function list(Request $request, $locate = 'tw')
|
|
|
25
|
+ public function list(Request $request, $locale = 'tw')
|
|
26
|
26
|
{
|
|
27
|
|
- $locate = $locate == "tw" ? "zh_TW" : $locate;
|
|
|
27
|
+ $locale = $locale == "tw" ? "zh_TW" : $locale;
|
|
28
|
28
|
$request_ordering = $request->ordering ?? "desc";
|
|
29
|
29
|
$result = [];
|
|
30
|
30
|
|
|
|
@@ -37,11 +37,11 @@ class NewsController extends Controller
|
|
37
|
37
|
$result["top"][] = [
|
|
38
|
38
|
"id" => $top->id,
|
|
39
|
39
|
"categoryId" => $top->news_category_id,
|
|
40
|
|
- "category" => $top->newsCategory->getTranslation("name", $locate),
|
|
|
40
|
+ "category" => $top->newsCategory->getTranslation("name", $locale),
|
|
41
|
41
|
"postDate" => Carbon::parse($top->post_date)->format("Y/m/d"),
|
|
42
|
|
- "title" => $top->getTranslation("title", $locate),
|
|
|
42
|
+ "title" => $top->getTranslation("title", $locale),
|
|
43
|
43
|
"imgUrl" => $top->news_img_url,
|
|
44
|
|
- "imgAlt" => $top->getTranslation("news_img_alt", $locate),
|
|
|
44
|
+ "imgAlt" => $top->getTranslation("news_img_alt", $locale),
|
|
45
|
45
|
];
|
|
46
|
46
|
|
|
47
|
47
|
//文章列表
|
|
|
@@ -51,27 +51,27 @@ class NewsController extends Controller
|
|
51
|
51
|
$result["list"][] = [
|
|
52
|
52
|
"id" => $item->id,
|
|
53
|
53
|
"categoryId" => $item->news_category_id,
|
|
54
|
|
- "category" => $item->newsCategory->getTranslation("name", $locate),
|
|
|
54
|
+ "category" => $item->newsCategory->getTranslation("name", $locale),
|
|
55
|
55
|
"postDate" => Carbon::parse($item->post_date)->format("Y/m/d"),
|
|
56
|
|
- "title" => $item->getTranslation("title", $locate),
|
|
|
56
|
+ "title" => $item->getTranslation("title", $locale),
|
|
57
|
57
|
"imgUrl" => $item->news_img_url,
|
|
58
|
|
- "imgAlt" => $item->getTranslation("news_img_alt", $locate),
|
|
|
58
|
+ "imgAlt" => $item->getTranslation("news_img_alt", $locale),
|
|
59
|
59
|
];
|
|
60
|
60
|
}
|
|
61
|
61
|
return Response::ok($result);
|
|
62
|
62
|
}
|
|
63
|
63
|
|
|
64
|
64
|
public function detail($locale = 'tw', $id){
|
|
65
|
|
- $locate = $locale == "tw" ? "zh_TW" : $locale;
|
|
|
65
|
+ $locale = $locale == "tw" ? "zh_TW" : $locale;
|
|
66
|
66
|
$news = News::find($id);
|
|
67
|
67
|
$paragraphs = [];
|
|
68
|
68
|
foreach($news->paragraphs as $paragraph){
|
|
69
|
69
|
$paragraphs[] = [
|
|
70
|
70
|
"type" => $paragraph->contentType(),
|
|
71
|
71
|
"imgUrl" => $paragraph->paragraph_img,
|
|
72
|
|
- "alt" => $paragraph->getTranslation("img_alt", $locate),
|
|
|
72
|
+ "alt" => $paragraph->getTranslation("img_alt", $locale),
|
|
73
|
73
|
"imgOutLink" => $paragraph->image_link,
|
|
74
|
|
- "content" => nl2br($paragraph->getTranslation("text_content", $locate)),
|
|
|
74
|
+ "content" => nl2br($paragraph->getTranslation("text_content", $locale)),
|
|
75
|
75
|
];
|
|
76
|
76
|
}
|
|
77
|
77
|
|
|
|
@@ -85,28 +85,28 @@ class NewsController extends Controller
|
|
85
|
85
|
$otherNewsList[] = [
|
|
86
|
86
|
"id" => $item->id,
|
|
87
|
87
|
"categoryId" => $item->newsCategory->id,
|
|
88
|
|
- "category" => $item->newsCategory->getTranslation("name", $locate),
|
|
|
88
|
+ "category" => $item->newsCategory->getTranslation("name", $locale),
|
|
89
|
89
|
"postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
|
|
90
|
|
- "title" => $item->getTranslation("title", $locate),
|
|
|
90
|
+ "title" => $item->getTranslation("title", $locale),
|
|
91
|
91
|
"imgUrl" => $item->news_img_url,
|
|
92
|
|
- "imgAlt" => $item->getTranslation("news_img_alt", $locate),
|
|
93
|
|
- "written" => $item->getTranslation("written_by", $locate),
|
|
94
|
|
- "description" => $item->getTranslation("description", $locate),
|
|
|
92
|
+ "imgAlt" => $item->getTranslation("news_img_alt", $locale),
|
|
|
93
|
+ "written" => $item->getTranslation("written_by", $locale),
|
|
|
94
|
+ "description" => $item->getTranslation("description", $locale),
|
|
95
|
95
|
];
|
|
96
|
96
|
}
|
|
97
|
97
|
$result = [
|
|
98
|
98
|
"id" => $news->id,
|
|
99
|
99
|
"categoryId" => $news->newsCategory->id,
|
|
100
|
|
- "category" => $news->newsCategory->getTranslation("name", $locate),
|
|
|
100
|
+ "category" => $news->newsCategory->getTranslation("name", $locale),
|
|
101
|
101
|
"postDate" => Carbon::parse($news->post_date)->format("Y.m.d"),
|
|
102
|
|
- "title" => $news->getTranslation("title", $locate),
|
|
|
102
|
+ "title" => $news->getTranslation("title", $locale),
|
|
103
|
103
|
"imgUrl" => $item->news_img_url,
|
|
104
|
|
- "imgAlt" => $item->getTranslation("news_img_alt", $locate),
|
|
105
|
|
- "written" => $news->getTranslation("written_by", $locate),
|
|
106
|
|
- "description" => $news->getTranslation("description", $locate),
|
|
107
|
|
- "metaTitle" => $news->getTranslation("meta_title", $locate),
|
|
108
|
|
- "metaKeyword" => $news->getTranslation("meta_keyword", $locate),
|
|
109
|
|
- "metaDesc" => $news->getTranslation("meta_description", $locate),
|
|
|
104
|
+ "imgAlt" => $item->getTranslation("news_img_alt", $locale),
|
|
|
105
|
+ "written" => $news->getTranslation("written_by", $locale),
|
|
|
106
|
+ "description" => $news->getTranslation("description", $locale),
|
|
|
107
|
+ "metaTitle" => $news->getTranslation("meta_title", $locale),
|
|
|
108
|
+ "metaKeyword" => $news->getTranslation("meta_keyword", $locale),
|
|
|
109
|
+ "metaDesc" => $news->getTranslation("meta_description", $locale),
|
|
110
|
110
|
"metaImg" => $news->meta_img,
|
|
111
|
111
|
"paragraphs" => $paragraphs,
|
|
112
|
112
|
"otherNews" => $otherNewsList
|