2017-03-13 55 views
0

我有一個看起來很簡單的問題。Laravel過濾器嵌套集合

我會很快解釋實際問題:

  1. 一個無線電有很多座標
  2. 我收集了收音機
  3. 我想過濾基於條件的座標
  4. 下面的代碼由於某種原因不起作用。

    $radios = $radios->map(function ($radio, $key) { 
    
        $coordinates = $radio->coordinates; 
        $coordinates = $coordinates->filter(function($coordinate, $key) { 
    
         // return true or false; 
        }); 
    
        $radio['coordinates'] = $coordinates; 
    
        return $radio; 
    }); 
    

我可以過濾收集座標,但不能「附加」經濾波的陣列到無線電對象。
我在做什麼錯?

回答

0

編輯:

試圖改變自己的功能,這一點:

$radios = $radios->map(function ($radio, $key) { 

    $coordinates = $radio->coordinates; 
    $coordinates = $coordinates->filter(function($coordinate, $key) { 

     // return true or false; 
    }); 

     $radio[$key] = $coordinates; 

     return $radio; 
    }); 
+0

我不知道我跟隨。請你詳細說明一下嗎? –

+0

無線電返回什麼? – Onix

+0

它應該返回一個帶有座標集合的收音機,其中一些座標被過濾掉。但是當我返回Response :: json($ radios-> values() - > all());我得到未過濾的座標集合。 –