public function scopeSearch(Builder $query, ?string $search = null): Builder 	{ 		$search = preg_replace('/\s+/', '%', $search ?? ''); 		$search = empty($search) ? null : '%' . $search . '%';  		return !$search ? $query : $query->where(function (Builder $query) use ($search) { 			$query->where('ip_address', 'like', $search) 			->orWhere('control_number', 'like', $search) 			->orWhereHas('latestMetadata', function ($query) use ($search) { 				$query->where('user_agent', 'like', $search) 				->orWhere('screen_width', 'like', $search) 				->orWhere('screen_height', 'like', $search) 				->orWhere('platform', 'like', $search) 				->orWhere('browser', 'like', $search) 				->orWhere('device', 'like', $search); 			}); 		}); 	}