如何通过“ LIKE”过滤字段并将结果计入此Laravel图表?

时间:2019-11-03 03:25:46

标签: php laravel

我正在尝试修复一个仪表板,在该仪表板上有一些小部件可以显示我已经有多少票,但是可以通过名为ConnectionError: HTTPConnectionPool(host='{ckan.site_url value, in this case the public IP of the instance}', port=80): Max retries exceeded with url: /api/3/action/resource_show (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f3bb0151490>: Failed to establish a new connection: [Errno 110] Connection timed out',))的列进行过滤(状态为诸如 pending 之类的字符串, 已解决已停止等)放入名为status的表中。

我尝试从此代码的许多部分中放入chamados的许多组合,但没有成功。有人可以帮助我向我展示如何过滤此类信息吗?

这是Controller中的代码:

->where('status', 'like', '%finished')

这是我的观点:

$settings5 = [
    'chart_title'           => 'Chamados pendentes',
    'chart_type'            => 'number_block',
    'report_type'           => 'group_by_date',
    'model'                 => 'App\\Chamado',
    'group_by_field'        => 'prazo',
    'group_by_period'       => 'day',
    'aggregate_function'    => 'count',
    'filter_field'          => 'created_at',
    'group_by_field_format' => 'd-m-Y H:i:s',
    'column_class'          => 'col-md-3',
    'entries_number'        => '5', 
];

$settings5['total_number'] = 0;

if (class_exists($settings5['model'])) {
    $settings5['total_number'] = $settings5['model']::when(isset($settings5['filter_field']), function ($query) use ($settings5) {
        if (isset($settings5['filter_days'])) {
            return $query->where($settings5['filter_field'], '>=', now()->subDays($settings5['filter_days'])->format('Y-m-d'));
        } elseif (isset($settings5['filter_period'])) {
            switch ($settings5['filter_period']) {
                case 'week':
                    $start = date('Y-m-d', strtotime('last Monday'));
                    break;
                case 'month':
                    $start = date('Y-m') . '-01';
                    break;
                case 'year':
                    $start  = date('Y') . '-01-01';
                    break;
            }
            if (isset($start)) {
                return $query->where($settings5['filter_field'], '>=', $start);
            }
        }
    })
    ->{$settings5['aggregate_function'] ?? 'count'}($settings5['aggregate_field'] ?? '*');
}

在这个例子中,我必须显示票数“ pendentes”(葡萄牙语)。有人可以向我解释我在做什么以及如何做吗?

0 个答案:

没有答案