parent
commit
0f9a344509

+ 3
- 3
app/Http/Controllers/Api/HistoryController.php View File

@@ -20,9 +20,9 @@ class HistoryController extends Controller
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 26
         $data = History::where("visible", 1)->orderByDesc("selected_year", "desc")->orderByDesc("selected_month")->get();
27 27
         $yearList = History::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
28 28
         $result = [];
@@ -30,7 +30,7 @@ class HistoryController extends Controller
30 30
         foreach($data as $item){
31 31
             $result["list"][$item->selected_year][] = [
32 32
                 "operateMonth " => $item->selected_year . "." . $item->selected_month,
33
-                "title" => $item->getTranslation("title", $locate),
33
+                "title" => $item->getTranslation("title", $locale),
34 34
                 "imgUrl" => $item->img_url_link
35 35
             ];
36 36
         }

+ 4
- 4
app/Http/Controllers/Api/HomePageController.php View File

@@ -24,9 +24,9 @@ class HomePageController extends Controller
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 30
         $result = [];
31 31
 
32 32
         $webNews = News::where("visible", 1)->orderByDesc("post_date")->limit(3)->get();
@@ -34,9 +34,9 @@ class HomePageController extends Controller
34 34
             $result["list"][] = [
35 35
                 "id" => $item->id,
36 36
                 "categoryId" => $item->newsCategory->id,
37
-                "category" => $item->newsCategory->getTranslation("name", $locate),
37
+                "category" => $item->newsCategory->getTranslation("name", $locale),
38 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 42
         return Response::ok($result);

+ 24
- 24
app/Http/Controllers/Api/NewsController.php View File

@@ -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

+ 5
- 5
app/Http/Controllers/Api/ProfilePageController.php View File

@@ -21,17 +21,17 @@ class ProfilePageController extends Controller
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 27
         $data = ProfilePart::where("visible", 1)->orderByDesc("order")->get();
28 28
         $result = [];
29 29
         foreach($data as $item){
30 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 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 37
         return Response::ok($result);

+ 12
- 12
app/Http/Controllers/Api/ProjectController.php View File

@@ -25,10 +25,10 @@ class ProjectController extends Controller
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 30
         $categoryId = $request->input("categoryId") ?? "";
31
-        $locate = $locate == "tw" ? "zh_TW" : $locate;
31
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
32 32
         $result = [];
33 33
 
34 34
         //年份清單
@@ -55,10 +55,10 @@ class ProjectController extends Controller
55 55
             $result["list"][] = [
56 56
                 "id" => $project->id,
57 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 60
                 "tags" => $project->tags->pluck('name', 'id')->all(),
61
-                "name" => $project->getTranslation("name", $locate),
61
+                "name" => $project->getTranslation("name", $locale),
62 62
                 "imgUrl" => $project->first_list_img_url
63 63
             ];
64 64
         }
@@ -67,7 +67,7 @@ class ProjectController extends Controller
67 67
 
68 68
     public function detail($locale = 'tw', $id){
69 69
 
70
-        $locate = $locale == "tw" ? "zh_TW" : $locale;
70
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
71 71
         $project = Project::find($id);
72 72
 
73 73
         $projectHistories = [];
@@ -84,9 +84,9 @@ class ProjectController extends Controller
84 84
             "subName" => $project->getTranslation("sub_name", $locale),
85 85
             "description" => $project->getTranslation("description", $locale),
86 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 90
             "metaImg" => $project->meta_img,
91 91
             "region_id" => $project->region_id,
92 92
             "region" => $project->region->getTranslation("name", $locale),
@@ -108,18 +108,18 @@ class ProjectController extends Controller
108 108
     }
109 109
 
110 110
     public function badges($locale = 'tw') {
111
-        $locate = $locale == "tw" ? "zh_TW" : $locale;
111
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
112 112
 
113 113
         $projects = Project::where("badge_type", 2)->get();
114 114
         $result = [];
115 115
 
116 116
         foreach($projects as $project){
117
-            $badgesData = $project->awardBadges();
117
+            $badgesData = $project->awardBadges;
118 118
             $badges = [];
119 119
             foreach($badgesData as $badge){
120 120
                 $badges[] = [
121 121
                     "imgUrl" => $badge->imgUrlLink,
122
-                    "name" => $badge->getTranslation("name", $locale),
122
+                    "name" => $badge->getTranslation("title", $locale),
123 123
                     "rewardYear" => "取得時間 : " . date("Y.m", strtotime($badge->award_date))
124 124
                 ];
125 125
             }

+ 3
- 5
app/Models/Project.php View File

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