How about:
$companies = Company::select('companies.*')
->with('ratings')
->leftJoin('ratings', 'companies.id', 'ratings.company_id')
->where('name', 'like', "%{$name}%")
->groupBy('companies.id')
->having(DB::raw('AVG(ratings.rating)'), '>=', $request->rating_min)
->paginate($request->get('per_page', 10));
This will give you all companies that have an average rating over or equal to the specified minimum rating.
That's the rough idea, but you would need to tweak the logic a bit only include the leftJoin, the groupBy and the having when $request->rating_min is present.
P.S., don't forget to add use Illuminate\Support\Facades\DB; at the top of your file.
Also, if you don't need to access ->ratings on your individual models, you can take out ->with('ratings').