Get empty columns in laravel collection - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Tuesday, December 7, 2021

Get empty columns in laravel collection

I have this Laravel collection, obtained from a DB query:

$c = collect(\DB::connection('mysql_scipg')
     ->table('producao_email')
     ->where('cod_cliente', $cliente_id)
     ->where('lote',$lote)
     ->whereIn('cod_status',$statusCliente)
     ->select('dominio','lote','sv_email','cod_status')
     ->get());

The problem i'm encountering is, getting data from the collection, in cases where sv_email is different of "":

example:

there are cases where sv_email is filled in and cases where sv_email = "", sv email is either with information or "", note is not null, it is " ";

in the image below, I presented a case where sv_email = ""

using the command:

dd ($c-> where ('sv_email', '')

collection where sv_email = ""

I tested the command dd($c->where('sv_email','SVV095')

collection where sv_email != ""

the problem occurs when I try to get sv_email, in cases where it is different from ""

I tested:


    dd($c->where('sv_email','<>',"");
    dd($c->where('sv_email','<>','');
    dd($c->where('sv_email','!=',"");
    dd($c->where('sv_email','!=','');

all returned an empty collection.

there is a case where it returns as I wish. But I have to do another query, and I don't want this way, because I would have to do 2 queries in the DB to get the data, and I can manipulate the collection, where am I going wrong?

the case where it works would be:


    $c_2 = collect(\DB::connection('mysql_scipg')
           ->table('producao_email')
           ->where('cod_cliente', $cliente_id)
           ->where('lote',$lote)
           ->where('sv_email','!=','')
           ->select('dominio','lote','sv_email','cod_status')
           ->get());



source https://stackoverflow.com/questions/70249070/get-empty-columns-in-laravel-collection

No comments:

Post a Comment