Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
Laravel 5.4 - Query relationship with search termn

i'm working in laravel 5.4, i have this tables:

PROJECT | id | tags | title |

PRODUCT | id | project_id | category_id |

CATEGORY | id | name |

The tags of project is a string separated by comma:

tag1,tag2,tag3...

The first step that i need is filter projects by termn:

$termn = 'examples';
$projects = Project::where('tags', 'LIKE' , '%'.$termn.'%')->paginate(20);

it work well, but i would like get all product's project with a specific "category_id".

My relations models is working well.

Thank you for your help! this is the first time that i'm trying to do something like this.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Use with() method:

Project::where('tags', 'like' , '%'.$termn.'%')
       ->with(['products' => function($q) use($categoryId) {
           $q->where('category_id', $categoryId);
       }])
       ->paginate(20);
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda