How to delete a record of a collection?

0

At the time of returning the result of a query I want to debug the result, my intention is, if it does not comply with the condition that is eliminated from the matrix, however all are eliminated, this is an example of the result:

{
    "0": {
        "id": 4,
        "codigo": "6WQRLIRO",
        "nombre": "proo3",
        "fecha_emision": "2017-10-08",
        "fecha_limite": "2017-10-28",
        "activa": "si",
        "created_at": "2017-10-18 12:53:12",
        "updated_at": "2017-10-18 12:53:12",
        "descripcion": null,
        "url": null,
        "condiciones": []
    },
    "2": {
        "id": 6,
        "codigo": "QDA6M-6P",
        "nombre": "Garrafón gratis",
        "fecha_emision": "2017-10-01",
        "fecha_limite": "2017-11-30",
        "activa": "no",
        "created_at": "2017-10-20 08:47:55",
        "updated_at": "2017-10-20 08:47:55",
        "descripcion": null,
        "url": null,
        "condiciones": [
            {
                "id": 2,
                "promocion_id": 6,
                "tipo_condicion": "sexo",
                "valor_condicion": "mujer",
                "created_at": "2017-10-20 08:47:55",
                "updated_at": "2017-10-20 08:47:55"
            },
            {
                "id": 3,
                "promocion_id": 6,
                "tipo_condicion": "padre/madre",
                "valor_condicion": "padre/madre",
                "created_at": "2017-10-20 08:47:55",
                "updated_at": "2017-10-20 08:47:55"
            }
        ]
    }
}

This is the code:

foreach ($promociones as $key => $promocion) {
        if ($promocion->nombre == 'Circulo') {
          $promociones->forget($key);
        }
        foreach ($promocion->condiciones as $condicion) {
          if ($condicion->tipo_condicion == 'colonia') {
            if ($condicion->valor_condicion != $colonia) {
              $promociones->forget($key);

            }
          }

        }
      }

What I intend is to eliminate only the one that does not meet the condition, however all those that have any kind of conditions are deleted

    
asked by BorrachApps Mex 15.11.2017 в 17:44
source

1 answer

0

The error could be in the variable $colonia (you can not see the value in the example presented) , since if $colonia is null, or has a value not contained in any condition, all promotions will be eliminated.

    
answered by 15.11.2017 в 21:57