too long

I am dynamically adding conditional where statements in Laravel Query Builder.

$whereClause = array(
                       $field_name1 => $field_value1,
                       $field_name2 => $field_value2,
                       $field_name3 => $field_value3
            );

 $factories = DB::table('factories')
                ->where($whereClause)
                ->orderBy('ipo', 'desc')
                ->paginate(15);

The above working just fine, the problem is that I need to add third pram 'like' of where statement ->where('name', 'like', '%' . $search_text . '%') in the $whereClause array, how can I do that?

You need to use another array if you want to use an operator. So, your array will look like this:

$whereClause = [
    $field_name1 => $field_value1,
    $field_name2 => $field_value2,
    $field_name3 => $field_value3,
    [$field_name4, 'like', '%something%']
]