HAVING() Unknown column in Laravel Eloquent

  eloquent, laravel

I have this working code with AS count self declared field using eloquent

$delimeter = ' ';
$keywords = explode($delimeter, $keyword_search); 
$base_query = DB::table('yeast_entire_search')->selectRaw('
        id,
        part_number, 
        part_name,
Round ((Char_length(Concat(
        LOWER(part_number), 
        LOWER(part_name)
    )) 
    - 
    Char_length(REPLACE ( Concat(
        LOWER(part_number), 
        LOWER(part_name)

    ), LOWER("'.$keyword_search.'"), ""))) / Char_length(LOWER("'.$keyword_search.'")))  AS count 
 ');
foreach($keywords as $keyword){
    $base_query->where(function($query) use ($keyword){
            $query->where('part_number', 'like', '%' . $keyword . '%') 
                ->orWhere('part_name', 'like', '%' . $keyword . '%');
    });
}
$data = $base_query->orderBy('count','DESC')->paginate(20);
return $data;

But when I tried to add havingRaw() like this

$data = $base_query->orderBy('count','DESC')->havingRaw(' count > 0 ')->paginate(20);
return $data;

But Im getting an error like this

enter image description here

Source: Laravel

Leave a Reply