-1
I’m in need of some help!
I have an SQL query in Laravel as follows:
$cliente = DB::table('clientes')->where(DB::raw("cpf = '$cpf' AND (REPLACE(REPLACE(REPLACE(REPLACE(telefone1_num, '(', ''), ')',''), '-',''),' ','') LIKE '%$telefone%' OR REPLACE(REPLACE(REPLACE(REPLACE(telefone2_num, '(', ''), ')',''), '-',''),' ','') LIKE '%$telefone%' OR REPLACE(REPLACE(REPLACE(REPLACE(telefone3_num, '(', ''), ')',''), '-',''),' ','') LIKE '%$telefone%')"))->first();
I simply need to check if she’s returned any results. I’ve tried it this way:
if (is_null($cliente) || $cliente == null ) {
return $this->sendError(config('global.cliente_nao_encontrado'));
}
But you still get into if
. Does anyone know what it can be?
Make sure SQL returns results?
– Woss
Yes friend! I tested it here already! In it I just remove the mask normally and compare!
– Christian Jorge
Ever tried a dd($client); ?
– user38174
the comparison
is_null($cliente)
and$cliente == null
are the same thing; try to use the methodexists()
;$client->exists()
– RFL
@RFL are not the same thing. A checks if it is null, the other if it is equal null. It looks the same, but how is used the loose comparison, the value
false
, for example, does not satisfy the first, but satisfies the second.– Woss
@Andersoncarloswoss is true, I had forgotten the
==
, I ended up writing==
thinking about===
– RFL
Guys, I was able to solve, the consultation in written Laravel for some reason includes a
is null
at the end of SQL. In short, there was no return, I did otherwise and with this check even worked!– Christian Jorge