Search for null in collection stange result

Posted 1 week ago by Bvanhaastrecht

Hello,

When I request rows where some column is null, the return format is different then from searching that same column for a value.

With value:

$invoices->where('contract_id', '00000185');

object(Illuminate\Database\Eloquent\Collection)#785 (1) {
["items":protected]=>
array(19) {
[0]=>
object(App\Models\CustomerInvoices)#817 (26) {

In JSON looks like (correctly):

[{
    "column1" : "data",
    "column2" : "data",
},
    "column1" : "data",
    "column2" : "data",
}]

Search for null:

$invoices->where('contract_id', null);

object(Illuminate\Database\Eloquent\Collection)#785 (1) {
["items":protected]=>
array(5) {
[19]=>
object(App\Models\CustomerInvoices)#836 (26) { ...

In JSON looks like (incorrect, different from with value search):

{
    "19": {
        "column1" : "data",
    "column2" : "data",
    },
    "20": {
        "column1" : "data",
    "column2" : "data",
    }
}

So you see with search for null each row gets a key. Because I'm outputing directory to json, I would like both outputs to look the same. Any idea why this happens?

Regards, Bastiaan

Please sign in or create an account to participate in this conversation.