2017-10-18 223 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。请查看我发布我的模型和控制器的链接。你能简化它吗? –