Jump to content

Query para pesquisa em 3 tabelas


Toninho

Recommended Posts

Salve,

essa query não esta funcionando, quero pesquisar em 3 tabela

$keyword=ucwords(strtolower(str_replace('-'," ", $urcityy[2])));				
				$data = Empresa::where('city',$urcityyyy)->where('title','like','%'.$keyword.'%')
               ->orWhereHas('empregos', function($q) use ($keyword){
                    return $q->where('title','like','%'. $keyword . '%')->where('city',$urcityyyy);
               })
               ->orWhereHas('eventos', function($q) use ($keyword){
                    return $q->where('title','like','%'. $keyword . '%')->where('city',$urcityyyy);
               })->get();

Grato

Link to comment
Share on other sites

  • 1 month later...
On 2/10/2023 at 12:56 AM, Toninho said:

Salve,

essa query não esta funcionando, quero pesquisar em 3 tabela

$keyword=ucwords(strtolower(str_replace('-'," ", $urcityy[2])));				
				$data = Empresa::where('city',$urcityyyy)->where('title','like','%'.$keyword.'%')
               ->orWhereHas('empregos', function($q) use ($keyword){
                    return $q->where('title','like','%'. $keyword . '%')->where('city',$urcityyyy);
               })
               ->orWhereHas('eventos', function($q) use ($keyword){
                    return $q->where('title','like','%'. $keyword . '%')->where('city',$urcityyyy);
               })->get();

Grato

Aparentemente você está a utilizar Laravel correcto (ou algum framework muito parecido com que usa o Builder do Eloquent)?

 

Sua query é muito complexa e eu oriento neste caso a utilizar uma raw query por exemplo:

 

SELECT <campos>

from 

<tabela principal>

left join <tabela 1> on <tabela principal>.<campo> = <tabela 2>.<campo co-relato>

left join <tabela 2> on <tabela principal>.<campo> = <tabela 3>.<campo co-relato>

left join <tabela 3> on <tabela principal>.<campo> = <tabela 3>.<campo co-relato>

where

 <campos que você citou acima>

 

Edited by messhias
Editar campos para melhor visualização
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.