Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 2 years ago.
0
Solution

First of all, your original query for the "productos" table can be simplified, you don't need the function for this where, just:

$busqueda = DB::table('productos')->where('nombre', 'LIKE', '%'. $term .'%');

For the other related tables, you should do a JOIN (you can read about it on MySQL site), which is basically "mix" two tables into one specifying some conditions, your code can look like this:

$busqueda = DB::table('baterias')->join('marca_baterias', 'baterias.marca_bateria', '=', 'marca_baterias.id')->where('marca_baterias.nombre', 'LIKE', '%'. $term .'%');

And exactly the same for the neumaticos/marca_neumaticos tables.

Last updated 2 years ago.
0

Thanks ayoze! I understand that it is impossible to unify everything in a single query, then I need to create a query for each table and then collect the data in a temporary array. ?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.