Query in Laravel using SQL tags Like, where, and, or

0

Good afternoon guys, I'm having a problem because I need to make the following query representation in laravel

SELECT * FROM imovels   AS i
INNER JOIN estados      AS e ON e.id = i.estado_id 
INNER JOIN cidades      AS c ON c.id = i.cidade_id
INNER JOIN bairros      AS b ON b.id = i.bairro_id
INNER JOIN tipos        AS t ON t.id = i.tipo_id
INNER JOIN finalidades          AS f ON f.id = i.finalidade_id


WHERE 
(i.finalidade_id = finalidadeId OR finalidadeId IS NULL) AND
(i.tipo_id = tipoId OR tipoId IS NULL) AND
(
i.titulo                        LIKE CONCAT('%',termo,'%') OR
i.descricao                     LIKE CONCAT('%',termo,'%') OR
i.valor                     LIKE CONCAT('%',termo,'%') OR
i.rua                   LIKE CONCAT('%',termo,'%') OR
i.codigo_interno                LIKE CONCAT('%',termo,'%') OR
e.nome                  LIKE CONCAT('%',termo,'%') OR
c.nome                  LIKE CONCAT('%',termo,'%') OR
b.nome                  LIKE CONCAT('%',termo,'%') OR
t.nome                  LIKE CONCAT('%',termo,'%') OR
f.nome                  LIKE CONCAT('%',termo,'%') );

But when I use

DB::table('imovels')->orWhere('tipos.nome', 'LIKE', '%' . $request->q . '%')

I can access for ex. the type name property but the array gets mounted differently than when I do with

Imovel::with('imagens', 'estado', 'cidade', 'bairro', 'user', 'tipo', 'finalidade')

The array gets mounted correctly but I can not compare the properties of the relation tables.

I do not know if I can be clear. But I appreciate any kind of help.

    
asked by anonymous 12.08.2016 / 17:13

0 answers