I need to apply the same join i do in this code, but in another code i build it with EloquentBuilder $query
The join I want is this:
$afiliates = DB::table('ad_afiliado as af')
->join('af_promocion as promo', 'af.Clave', '=', 'promo.id_afiliado')
->select('af.logo_url', 'af.NombreComercial', 'af.Destacado', 'af.id_afiliado', 'af.Clave', 'af.DestacadoInicio')
->where('promo.v_fin','>',$FechaActual)
->paginate(9);
The Code where I want to put the join is this:
$afiliates = AdAfiliado::query()
->where('Activo','=', 'S')
->where(function (IlluminateDatabaseEloquentBuilder $query) use ($request) {
$query->orWhere('NombreComercial', 'like', "%{$request->search}%");
$query->orWhere('Etiqueta', 'like', "%{$request->search}%");
$query->orWhere('Categoria', 'like', "{$request->search}");
})
->orderBy('CLAVE', $request->order)
->paginate(9);
I appreciate your help!
2
Answers
https://ashallendesign.co.uk/blog/using-query-in-laravel-eloquent-queries
the query() method is not necesary, so i removed it, and did it in DB::table way.
I also removed the route IlluminateDatabaseEloquentBuilder
The resulting code is this:
You can use
whereHas()
using the relation between AdAfiliado and AfPromocion