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.
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. ?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community