2017-10-18 225 views
0

這是我的結果樹,我想通過「LANGUAGE_CODE」過濾領域一個特定的字段進行篩選像陣列樹如何使用Laravel雄辯

"theme_detail": [ 
      { 
       "id": 1, 
       "parent_theme_id": null, 
       "image_url": "no_image", 
       "index_value": 1, 
       "status": "active", 
       "theme_detail": [ 
        { 
         "id": 4, 
         "theme_id": 1, 
         "language_code": "bn", 
         "theme_name": "থিম 1", 
         "theme_subtitle": "থিম 1 উপশিরোনাম", 
         "status": "active" 
        }, 
        { 
         "id": 1, 
         "theme_id": 1, 
         "language_code": "en", 
         "theme_name": "Theme 1", 
         "theme_subtitle": "Theme 1 Subtitle", 
         "status": "active" 
        } 
       ], 
       "parent_recursive": [ 
        { 
         "id": 2, 
         "parent_theme_id": 1, 
         "image_url": "no_image", 
         "index_value": 1, 
         "status": "active", 
         "theme_detail": [ 
          { 
           "id": 5, 
           "theme_id": 2, 
           "language_code": "bn", 
           "theme_name": "থিম 2", 
           "theme_subtitle": "থিম 2 উপশিরোনাম", 
           "status": "active" 
          }, 
          { 
           "id": 2, 
           "theme_id": 2, 
           "language_code": "en", 
           "theme_name": "Theme 2", 
           "theme_subtitle": "Theme 2 Subtitle", 
           "status": "active" 
          } 
         ], 
         "parent_recursive": [ 
          { 
           "id": 3, 
           "parent_theme_id": 2, 
           "image_url": "no_image", 
           "index_value": 1, 
           "status": "active", 
           "theme_detail": [ 
            { 
             "id": 3, 
             "theme_id": 3, 
             "language_code": "en", 
             "theme_name": "Theme 3", 
             "theme_subtitle": "Theme 3 Subtitle", 
             "status": "active" 
            }, 
            { 
             "id": 6, 
             "theme_id": 3, 
             "language_code": "bn", 
             "theme_name": "থিম 3", 
             "theme_subtitle": "থিম 3 উপশিরোনাম", 
             "status": "active" 
            } 
           ], 
           "parent_recursive": [ 
            { 
             "id": 4, 
             "parent_theme_id": 3, 
             "image_url": "no_image", 
             "index_value": 1, 
             "status": "active", 
             "theme_detail": [ 
              { 
               "id": 7, 
               "theme_id": 4, 
               "language_code": "bn", 
               "theme_name": "থিম 4", 
               "theme_subtitle": "থিম 4 উপশিরোনাম", 
               "status": "active" 
              }, 
              { 
               "id": 9, 
               "theme_id": 4, 
               "language_code": "en", 
               "theme_name": "Theme 4", 
               "theme_subtitle": "Theme 4 Subtitle", 
               "status": "active" 
              } 
             ], 
             "parent_recursive": [] 
            } 
           ] 
          }, 
          { 
           "id": 5, 
           "parent_theme_id": 2, 
           "image_url": "no_image", 
           "index_value": 1, 
           "status": "active", 
           "theme_detail": [ 
            { 
             "id": 8, 
             "theme_id": 5, 
             "language_code": "bn", 
             "theme_name": "থিম 5", 
             "theme_subtitle": "থিম 5 উপশিরোনাম", 
             "status": "active" 
            }, 
            { 
             "id": 10, 
             "theme_id": 5, 
             "language_code": "en", 
             "theme_name": "Theme 5", 
             "theme_subtitle": "Theme 5 Subtitle", 
             "status": "active" 
            } 
           ], 
           "parent_recursive": [] 
          } 
         ] 
        } 
       ] 
      } 
     ] 

這是我的JSON數組這是在像結構樹。 這個數組是遞歸雄辯關係的結果。 現在我想通過特定的語言代碼或任何其他字段來過濾它。 我怎樣才能用Laravel雄辯呢? 任何人都可以幫忙嗎?

+1

可以顯示雄辯奧姆查詢? –

+0

https://stackoverflow.com/questions/46708457/how-to-pass-parameter-from-controller-to-model-in-case-of-recursion。這是我已經發布我的模型和控制器的鏈接。請檢查一下。如果它能夠在雄辯的ORM級別上解決,那麼它對我更有幫助。 –

+0

你會得到'language_code'數組嗎?或者你會創建單個代碼? –

回答

0

你想讓你的最終迴應是這樣的:

'language_code' => [item_list] 
+0

我想要一個特定的language_code –

+0

的整個數組,您需要在這方面針對'theme_detail'&'parent_recursive'的Collections過濾器方法。然而,看看json數組的結構,這非常複雜。你需要先簡化它。 –

+0

https://stackoverflow.com/questions/46708457/how-to-pass-parameter-from-controller-to-model-in-case-of-recursion。請查看我發佈我的模型和控制器的鏈接。你能簡化它嗎? –