父節點
當前提交
0f9a344509

+ 3
- 3
app/Http/Controllers/Api/HistoryController.php 查看文件

20
     {
20
     {
21
     }
21
     }
22
 
22
 
23
-    public function list($locate = 'tw')
23
+    public function list($locale = 'tw')
24
     {
24
     {
25
-        $locate = $locate == "tw" ? "zh_TW" : $locate;
25
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
26
         $data = History::where("visible", 1)->orderByDesc("selected_year", "desc")->orderByDesc("selected_month")->get();
26
         $data = History::where("visible", 1)->orderByDesc("selected_year", "desc")->orderByDesc("selected_month")->get();
27
         $yearList = History::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
27
         $yearList = History::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
28
         $result = [];
28
         $result = [];
30
         foreach($data as $item){
30
         foreach($data as $item){
31
             $result["list"][$item->selected_year][] = [
31
             $result["list"][$item->selected_year][] = [
32
                 "operateMonth " => $item->selected_year . "." . $item->selected_month,
32
                 "operateMonth " => $item->selected_year . "." . $item->selected_month,
33
-                "title" => $item->getTranslation("title", $locate),
33
+                "title" => $item->getTranslation("title", $locale),
34
                 "imgUrl" => $item->img_url_link
34
                 "imgUrl" => $item->img_url_link
35
             ];
35
             ];
36
         }
36
         }

+ 4
- 4
app/Http/Controllers/Api/HomePageController.php 查看文件

24
     {
24
     {
25
     }
25
     }
26
 
26
 
27
-    public function list($locate = 'tw')
27
+    public function list($locale = 'tw')
28
     {
28
     {
29
-        $locate = $locate == "tw" ? "zh_TW" : $locate;
29
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
30
         $result = [];
30
         $result = [];
31
 
31
 
32
         $webNews = News::where("visible", 1)->orderByDesc("post_date")->limit(3)->get();
32
         $webNews = News::where("visible", 1)->orderByDesc("post_date")->limit(3)->get();
34
             $result["list"][] = [
34
             $result["list"][] = [
35
                 "id" => $item->id,
35
                 "id" => $item->id,
36
                 "categoryId" => $item->newsCategory->id,
36
                 "categoryId" => $item->newsCategory->id,
37
-                "category" => $item->newsCategory->getTranslation("name", $locate),
37
+                "category" => $item->newsCategory->getTranslation("name", $locale),
38
                 "postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
38
                 "postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
39
-                "title" => $item->getTranslation("title", $locate),
39
+                "title" => $item->getTranslation("title", $locale),
40
             ];
40
             ];
41
         }
41
         }
42
         return Response::ok($result);
42
         return Response::ok($result);

+ 24
- 24
app/Http/Controllers/Api/NewsController.php 查看文件

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
         $request_ordering = $request->ordering ?? "desc";
28
         $request_ordering = $request->ordering ?? "desc";
29
         $result = [];
29
         $result = [];
30
 
30
 
37
             $result["top"][] = [
37
             $result["top"][] = [
38
                 "id" => $top->id,
38
                 "id" => $top->id,
39
                 "categoryId" => $top->news_category_id,
39
                 "categoryId" => $top->news_category_id,
40
-                "category" => $top->newsCategory->getTranslation("name", $locate),
40
+                "category" => $top->newsCategory->getTranslation("name", $locale),
41
                 "postDate" => Carbon::parse($top->post_date)->format("Y/m/d"),
41
                 "postDate" => Carbon::parse($top->post_date)->format("Y/m/d"),
42
-                "title" => $top->getTranslation("title", $locate),
42
+                "title" => $top->getTranslation("title", $locale),
43
                 "imgUrl" => $top->news_img_url,
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
             $result["list"][] = [
51
             $result["list"][] = [
52
                 "id" => $item->id,
52
                 "id" => $item->id,
53
                 "categoryId" => $item->news_category_id,
53
                 "categoryId" => $item->news_category_id,
54
-                "category" => $item->newsCategory->getTranslation("name", $locate),
54
+                "category" => $item->newsCategory->getTranslation("name", $locale),
55
                 "postDate" => Carbon::parse($item->post_date)->format("Y/m/d"),
55
                 "postDate" => Carbon::parse($item->post_date)->format("Y/m/d"),
56
-                "title" => $item->getTranslation("title", $locate),
56
+                "title" => $item->getTranslation("title", $locale),
57
                 "imgUrl" => $item->news_img_url,
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
         return Response::ok($result);
61
         return Response::ok($result);
62
     }
62
     }
63
 
63
 
64
     public function detail($locale = 'tw', $id){
64
     public function detail($locale = 'tw', $id){
65
-        $locate = $locale == "tw" ? "zh_TW" : $locale;
65
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
66
         $news = News::find($id);
66
         $news = News::find($id);
67
         $paragraphs = [];
67
         $paragraphs = [];
68
         foreach($news->paragraphs as $paragraph){
68
         foreach($news->paragraphs as $paragraph){
69
             $paragraphs[] = [
69
             $paragraphs[] = [
70
                 "type" => $paragraph->contentType(),
70
                 "type" => $paragraph->contentType(),
71
                 "imgUrl" => $paragraph->paragraph_img,
71
                 "imgUrl" => $paragraph->paragraph_img,
72
-                "alt" => $paragraph->getTranslation("img_alt", $locate),
72
+                "alt" => $paragraph->getTranslation("img_alt", $locale),
73
                 "imgOutLink" => $paragraph->image_link,
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
             $otherNewsList[] = [
85
             $otherNewsList[] = [
86
                 "id" => $item->id,
86
                 "id" => $item->id,
87
                 "categoryId" => $item->newsCategory->id,
87
                 "categoryId" => $item->newsCategory->id,
88
-                "category" => $item->newsCategory->getTranslation("name", $locate),
88
+                "category" => $item->newsCategory->getTranslation("name", $locale),
89
                 "postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
89
                 "postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
90
-                "title" => $item->getTranslation("title", $locate),
90
+                "title" => $item->getTranslation("title", $locale),
91
                 "imgUrl" => $item->news_img_url,
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
         $result = [
97
         $result = [
98
             "id" => $news->id,
98
             "id" => $news->id,
99
             "categoryId" => $news->newsCategory->id,
99
             "categoryId" => $news->newsCategory->id,
100
-            "category" => $news->newsCategory->getTranslation("name", $locate),
100
+            "category" => $news->newsCategory->getTranslation("name", $locale),
101
             "postDate" => Carbon::parse($news->post_date)->format("Y.m.d"),
101
             "postDate" => Carbon::parse($news->post_date)->format("Y.m.d"),
102
-            "title" => $news->getTranslation("title", $locate),
102
+            "title" => $news->getTranslation("title", $locale),
103
             "imgUrl" => $item->news_img_url,
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
             "metaImg" => $news->meta_img,
110
             "metaImg" => $news->meta_img,
111
             "paragraphs" => $paragraphs,
111
             "paragraphs" => $paragraphs,
112
             "otherNews" => $otherNewsList
112
             "otherNews" => $otherNewsList

+ 5
- 5
app/Http/Controllers/Api/ProfilePageController.php 查看文件

21
     {
21
     {
22
     }
22
     }
23
 
23
 
24
-    public function list($locate = 'tw')
24
+    public function list($locale = 'tw')
25
     {
25
     {
26
-        $locate = $locate == "tw" ? "zh_TW" : $locate;
26
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
27
         $data = ProfilePart::where("visible", 1)->orderByDesc("order")->get();
27
         $data = ProfilePart::where("visible", 1)->orderByDesc("order")->get();
28
         $result = [];
28
         $result = [];
29
         foreach($data as $item){
29
         foreach($data as $item){
30
             $result["list"][] = [
30
             $result["list"][] = [
31
-                "title" => $item->getTranslation("title", $locate),
32
-                "content" => $item->getTranslation("content", $locate),
31
+                "title" => $item->getTranslation("title", $locale),
32
+                "content" => $item->getTranslation("content", $locale),
33
                 "imgUrl" => $item->img_url_link,
33
                 "imgUrl" => $item->img_url_link,
34
-                "alt" => $item->getTranslation("img_alt", $locate)
34
+                "alt" => $item->getTranslation("img_alt", $locale)
35
             ];
35
             ];
36
         }
36
         }
37
         return Response::ok($result);
37
         return Response::ok($result);

+ 12
- 12
app/Http/Controllers/Api/ProjectController.php 查看文件

25
     {
25
     {
26
     }
26
     }
27
 
27
 
28
-    public function list(Request $request, $locate = 'tw')
28
+    public function list(Request $request, $locale = 'tw')
29
     {
29
     {
30
         $categoryId = $request->input("categoryId") ?? "";
30
         $categoryId = $request->input("categoryId") ?? "";
31
-        $locate = $locate == "tw" ? "zh_TW" : $locate;
31
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
32
         $result = [];
32
         $result = [];
33
 
33
 
34
         //年份清單
34
         //年份清單
55
             $result["list"][] = [
55
             $result["list"][] = [
56
                 "id" => $project->id,
56
                 "id" => $project->id,
57
                 "region_id" => $project->region_id,
57
                 "region_id" => $project->region_id,
58
-                "region" => $project->region->getTranslation("name", $locate),
59
-                "address" => $project->getTranslation("address", $locate),
58
+                "region" => $project->region->getTranslation("name", $locale),
59
+                "address" => $project->getTranslation("address", $locale),
60
                 "tags" => $project->tags->pluck('name', 'id')->all(),
60
                 "tags" => $project->tags->pluck('name', 'id')->all(),
61
-                "name" => $project->getTranslation("name", $locate),
61
+                "name" => $project->getTranslation("name", $locale),
62
                 "imgUrl" => $project->first_list_img_url
62
                 "imgUrl" => $project->first_list_img_url
63
             ];
63
             ];
64
         }
64
         }
67
 
67
 
68
     public function detail($locale = 'tw', $id){
68
     public function detail($locale = 'tw', $id){
69
 
69
 
70
-        $locate = $locale == "tw" ? "zh_TW" : $locale;
70
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
71
         $project = Project::find($id);
71
         $project = Project::find($id);
72
 
72
 
73
         $projectHistories = [];
73
         $projectHistories = [];
84
             "subName" => $project->getTranslation("sub_name", $locale),
84
             "subName" => $project->getTranslation("sub_name", $locale),
85
             "description" => $project->getTranslation("description", $locale),
85
             "description" => $project->getTranslation("description", $locale),
86
             "images" => $project->img_list,
86
             "images" => $project->img_list,
87
-            "metaTitle" => $project->getTranslation("meta_title", $locate),
88
-            "metaKeyword" => $project->getTranslation("meta_keyword", $locate),
89
-            "metaDesc" => $project->getTranslation("meta_description", $locate),
87
+            "metaTitle" => $project->getTranslation("meta_title", $locale),
88
+            "metaKeyword" => $project->getTranslation("meta_keyword", $locale),
89
+            "metaDesc" => $project->getTranslation("meta_description", $locale),
90
             "metaImg" => $project->meta_img,
90
             "metaImg" => $project->meta_img,
91
             "region_id" => $project->region_id,
91
             "region_id" => $project->region_id,
92
             "region" => $project->region->getTranslation("name", $locale),
92
             "region" => $project->region->getTranslation("name", $locale),
108
     }
108
     }
109
 
109
 
110
     public function badges($locale = 'tw') {
110
     public function badges($locale = 'tw') {
111
-        $locate = $locale == "tw" ? "zh_TW" : $locale;
111
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
112
 
112
 
113
         $projects = Project::where("badge_type", 2)->get();
113
         $projects = Project::where("badge_type", 2)->get();
114
         $result = [];
114
         $result = [];
115
 
115
 
116
         foreach($projects as $project){
116
         foreach($projects as $project){
117
-            $badgesData = $project->awardBadges();
117
+            $badgesData = $project->awardBadges;
118
             $badges = [];
118
             $badges = [];
119
             foreach($badgesData as $badge){
119
             foreach($badgesData as $badge){
120
                 $badges[] = [
120
                 $badges[] = [
121
                     "imgUrl" => $badge->imgUrlLink,
121
                     "imgUrl" => $badge->imgUrlLink,
122
-                    "name" => $badge->getTranslation("name", $locale),
122
+                    "name" => $badge->getTranslation("title", $locale),
123
                     "rewardYear" => "取得時間 : " . date("Y.m", strtotime($badge->award_date))
123
                     "rewardYear" => "取得時間 : " . date("Y.m", strtotime($badge->award_date))
124
                 ];
124
                 ];
125
             }
125
             }

+ 3
- 5
app/Models/Project.php 查看文件

33
     public function badges()
33
     public function badges()
34
     {
34
     {
35
         return $this->morphToMany(Badge::class, 'badgeable')
35
         return $this->morphToMany(Badge::class, 'badgeable')
36
-        ->withPivot('award_date')  // ✅ 關鍵
36
+        ->withPivot('award_date', 'award_type')  // ✅ 關鍵
37
         ->withTimestamps();
37
         ->withTimestamps();
38
     }
38
     }
39
 
39
 
43
     public function targetBadges()
43
     public function targetBadges()
44
     {
44
     {
45
         return $this->morphToMany(Badge::class, 'badgeable')
45
         return $this->morphToMany(Badge::class, 'badgeable')
46
-            ->using(Badgeable::class)
47
-            ->wherePivot('award_type', 1)
48
             ->withPivot('award_type')
46
             ->withPivot('award_type')
47
+            ->wherePivot('award_type', 1)
49
             ->withTimestamps();
48
             ->withTimestamps();
50
     }
49
     }
51
 
50
 
55
     public function awardBadges()
54
     public function awardBadges()
56
     {
55
     {
57
         return $this->morphToMany(Badge::class, 'badgeable')
56
         return $this->morphToMany(Badge::class, 'badgeable')
58
-            ->using(Badgeable::class)
59
-            ->wherePivot('award_type', 2)
60
             ->withPivot('award_type', 'award_date')
57
             ->withPivot('award_type', 'award_date')
58
+            ->wherePivot('award_type', 2)
61
             ->withTimestamps();
59
             ->withTimestamps();
62
     }
60
     }
63
 
61