I have two queries that I'm building:
$color = \DB::table('colors')->take(10)->orderBy('id', 'desc');
if(isset($between)){
$color->whereBetween('id', [$start, $end]);
}
$flavor = \DB::table(\DB::raw('(' . $color->toSql() . ') as color'))
->join('flavor', 'flavor.color_id', '=', 'color.id')
->select('color.id', 'color.name', 'flavor.name');
return $flavor->get();
I need to bind 2 values in the first query only IF there is a $between set. And it has to be inside that \DB::raw.
How do I do that?
P.S if I run the first query separately it works perfectly. But when I try to run the whole query at once I'm getting General error 2031 (basically the parameters are not bind).