KIM-JINO5 2 dagar sedan
förälder
incheckning
36728ebdaa

+ 3 - 3
.env

@@ -9,11 +9,11 @@ LOG_DEPRECATIONS_CHANNEL=null
 LOG_LEVEL=debug
 
 DB_CONNECTION=mysql
-DB_HOST=db.web.or.kr
+DB_HOST=192.168.0.10
 DB_PORT=3306
 DB_DATABASE=web
 DB_USERNAME=admin
-DB_PASSWORD=bluescreen!!
+DB_PASSWORD=@@17125942KKh
 
 BROADCAST_DRIVER=log
 CACHE_DRIVER=redis
@@ -25,7 +25,7 @@ SESSION_LIFETIME=120
 MEMCACHED_HOST=
 
 REDIS_HOST=redis
-REDIS_PASSWORD=bluescreen!!
+REDIS_PASSWORD=@@17125942KKh
 REDIS_PORT=6379
 REDIS_DB=1
 REDIS_CACHE_DB=1

+ 13 - 8
app/Models/PostTag.php

@@ -187,11 +187,15 @@ class PostTag extends Model
      */
     public function getPostsByTag(SearchData $params): object
     {
+        // 태그 미선택(빈 값)이면 태그가 걸린 게시글 전체를 조회
+        $tag = $params->name ? trim($params->name) : null;
+        $tagCondition = $tag ? 'AND PSTG.tag = ?' : '';
+
         $sql = "
-            SELECT COUNT(DISTINCT PST.id) AS total FROM tb_post PST JOIN tb_post_tag PSTG ON PST.id = PSTG.post_id WHERE PST.is_delete = 0 AND PSTG.tag = ?;
+            SELECT COUNT(DISTINCT PST.id) AS total FROM tb_post PST JOIN tb_post_tag PSTG ON PST.id = PSTG.post_id WHERE PST.is_delete = 0 {$tagCondition};
         ";
 
-        $total = DB::selectOne($sql, [$params->name])->total;
+        $total = DB::selectOne($sql, $tag ? [$tag] : [])->total;
 
         $sql = "
              SELECT
@@ -212,7 +216,7 @@ class PostTag extends Model
             INNER JOIN tb_board BRD ON BRD.id = PST.board_id
             LEFT JOIN users USR ON USR.id = PST.user_id
             LEFT JOIN tb_post_tag PSTG_all ON PSTG_all.post_id = PST.id
-            WHERE PST.is_delete = 0 AND PSTG.tag = ?
+            WHERE PST.is_delete = 0 {$tagCondition}
             GROUP BY
                 PST.id, PST.board_id, PST.user_id, PST.subject, PST.created_at, BRD.name, BRD.code, USR.sid, USR.name
             ORDER BY
@@ -220,17 +224,18 @@ class PostTag extends Model
             LIMIT ? OFFSET ?;
         ";
 
-        $list = DB::select($sql, [
-            $params->name,
-            $params->perPage,
-            $params->offset
-        ]);
+        $list = DB::select($sql, $tag
+            ? [$tag, $params->perPage, $params->offset]
+            : [$params->perPage, $params->offset]
+        );
 
         $rows = count($list);
 
         return (object)[
             'total' => $total,
             'rows' => $rows,
+            'page' => $params->page,
+            'perPage' => $params->perPage,
             'list' => $list
         ];
     }

+ 19 - 22
public/js/board/tag.js

@@ -67,16 +67,23 @@ class ProcessTags
 
     async loadPosts(tag, page)
     {
+        // 빈/미지정 태그를 '' 로 정규화 (undefined/null 이 "undefined" 문자열로 전송되는 것 방지)
+        const t = (tag || '').trim();
+        page = parseInt(page, 10) || 1;
+
         const params = new URLSearchParams({
-            name: tag,
+            name: t,
             page: page
         });
 
-        this.updateQueryString(tag, page);
+        this.updateQueryString(t, page);
 
-        const nav = this.findLinkByTag(tag);
+        const nav = this.findLinkByTag(t);
         if (nav) {
             this.setActiveTag(nav);
+        } else {
+            // 전체 모드: 활성 태그 표시 해제
+            this.tags.querySelectorAll('.tag-nav-link.active').forEach(link => link.classList.remove('active'));
         }
 
         this.posts.innerHTML = ' \
@@ -131,11 +138,9 @@ class ProcessTags
         }
 
         if (target.classList.contains('active') && target.classList.contains('tag-nav-link')) {
-            this.posts.innerHTML = '<div class="text-center my-4">태그를 선택하면 게시글이 조회됩니다.</div>';
-            this.pagination.innerHTML = '';
+            // 활성 태그 재클릭 = 선택 해제 → 태그가 걸린 전체 게시글 조회
             target.classList.remove('active');
-            this.updateQueryString('', 0);
-            return;
+            return this.loadPosts('', 1);
         }
 
         let tag = (target.dataset.name || target.textContent || '').trim();
@@ -211,9 +216,10 @@ class ProcessTags
     
     renderPagination(res) 
     {
-        const total = parseInt(res.total || '0', 0) || 0;
+        const total = parseInt(res.total || '0', 10) || 0;
         const page = parseInt(res.page || '1', 10) || 1;
-        const last = Math.ceil(total / 10);
+        const perPage = parseInt(res.perPage || '10', 10) || 10;
+        const last = Math.ceil(total / perPage);
 
         if (last <= 1) {
             return;
@@ -245,23 +251,14 @@ class ProcessTags
         this.pagination.innerHTML = html;
     }
 
-    initFromUrl() 
+    initFromUrl()
     {
         const tag = this.getTagFromQuery();
-        if (!tag) {
-            return;
-        }
+        const page = this.getPageFromQuery();
 
+        // 태그가 목록에 존재하면 해당 태그로, 아니면(미선택/없는 태그) 태그 걸린 전체 게시글 조회
         const link = this.findLinkByTag(tag);
-        if (!link) {
-            return;
-        }
-
-        // 새로고침 시 active 유지
-        this.setActiveTag(link);
-
-        // 새로고침 시 자동 조회
-        this.fetchPosts({ target: link });
+        this.loadPosts(link ? tag : '', page);
     }
 }
 

+ 1 - 1
resources/views/desktop/layouts/app.blade.php

@@ -187,7 +187,7 @@
 
             <div class="ad-coupang">
                 <iframe src="https://coupa.ng/cdLzPn" width="100%" height="75" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
-                <iframe src="https://ads-partners.coupang.com/widgets.html?id=630891&template=carousel&trackingCode=AF0305179&subId=&width=200&height=150" width="100%" height="150" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
+                <iframe src="https://ads-partners.coupang.com/widgets.html?id=637907&template=carousel&trackingCode=AF0305179&subId=blog202302&width=200&height=150&tsource=" width="100%" height="150" frameborder="0" scrolling="no" referrerpolicy="unsafe-url" browsingtopics></iframe>
                 <small>
                     쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
                 </small>

+ 1 - 1
resources/views/mobile/board/tag.blade.php

@@ -5,7 +5,7 @@
     @if($tags->isEmpty())
         <p>등록된 태그가 없습니다.</p>
     @else
-        <h2>0개의 태그가 있습니다.</h2>
+        <h2>{{ number_format($tags->count()) }}개의 태그가 있습니다.</h2>
         <div id="tags">
             @foreach($tags as $tag)
                 <button class="tag-nav-link" data-name="{{ $tag->name }}">

+ 1 - 1
resources/views/mobile/layouts/app.blade.php

@@ -186,7 +186,7 @@
                 <!-- 쿠팡 광고 -->
                 <div class="ad-coupang">
                     <iframe src="https://coupa.ng/cdvhzK" width="100%" height="75" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
-                    <iframe src="https://ads-partners.coupang.com/widgets.html?id=637907&template=carousel&trackingCode=AF0305179&subId=&width=100&height=140" width="100%" height="140" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
+                    <iframe src="https://ads-partners.coupang.com/widgets.html?id=637907&template=carousel&trackingCode=AF0305179&subId=blog202302&width=100&height=140&tsource=" width="100%" height="140" frameborder="0" scrolling="no" referrerpolicy="unsafe-url" browsingtopics></iframe>
                     <small>
                         쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
                     </small>