Support the ongoing development of Laravel.io →
Database
Last updated 1 year ago.
0

Hi I found the solution, the problem was the groupBy('marca_auto.id_marca'), I was wrong, based on what grouping id_marca, so i need used productos.codigo_interno use and works perfect, I leave the solution if someone helps you

Change

->groupBy('marca_auto.id_marca')

To

->groupBy('productos.codigo_interno')

and move group tu down, the final code is

$productos = DB::table('productos as productos')
			->leftJoin('marcas_modelos_autos as marca_auto', 'marca_auto.codigo_interno', '=', 'productos.codigo_interno')
			->select('productos.id','productos.slug','productos.nombre','productos.precio')
			
			->where('marca_auto.id_marca', '=',  $id)
			->orWhereNotExists(function($query)
            {
                $query->select(DB::raw(('*')))
                	->from('marcas_modelos_autos as marca_auto')
                    ->whereRaw('marca_auto.codigo_interno = productos.codigo_interno');
                    
            })
            ->groupBy('productos.codigo_interno')
	        ->get();

Regards!!

Last updated 1 year 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.