1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Statistics\DataTables\Adminarea; |
6
|
|
|
|
7
|
|
|
use Rinvex\Statistics\Models\Geoip; |
8
|
|
|
use Illuminate\Database\Eloquent\Builder; |
9
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
10
|
|
|
use Cortex\Statistics\Transformers\Adminarea\GeoipTransformer; |
11
|
|
|
|
12
|
|
|
class GeoipsDataTable extends AbstractDataTable |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
protected $model = Geoip::class; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected $transformer = GeoipTransformer::class; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected $createButton = false; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Display ajax response. |
31
|
|
|
* |
32
|
|
|
* @return \Illuminate\Http\JsonResponse |
33
|
|
|
*/ |
34
|
|
|
public function ajax() |
35
|
|
|
{ |
36
|
|
|
return datatables($this->query()) |
|
|
|
|
37
|
|
|
->setTransformer(app($this->transformer)) |
38
|
|
|
->filterColumn('country_code', function (Builder $builder, $keyword) { |
39
|
|
|
$countryCode = collect(countries())->search(function ($country) use ($keyword) { |
40
|
|
|
return mb_strpos($country['name'], $keyword) !== false || mb_strpos($country['emoji'], $keyword) !== false; |
41
|
|
|
}); |
42
|
|
|
|
43
|
|
|
! $countryCode || $builder->where('country_code', $countryCode); |
44
|
|
|
}) |
45
|
|
|
->make(true); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get columns. |
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
protected function getColumns(): array |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'client_ip' => ['title' => trans('cortex/statistics::common.client_ip'), 'responsivePriority' => 0], |
57
|
|
|
'latitude' => ['title' => trans('cortex/statistics::common.latitude')], |
58
|
|
|
'longitude' => ['title' => trans('cortex/statistics::common.longitude')], |
59
|
|
|
'country_code' => ['title' => trans('cortex/statistics::common.country_code'), 'render' => 'full.country_emoji+" "+data'], |
60
|
|
|
'client_ips' => ['title' => trans('cortex/statistics::common.client_ips'), 'visible' => false], |
61
|
|
|
'is_from_trusted_proxy' => ['title' => trans('cortex/statistics::common.is_from_trusted_proxy')], |
62
|
|
|
'division_code' => ['title' => trans('cortex/statistics::common.division_code')], |
63
|
|
|
'postal_code' => ['title' => trans('cortex/statistics::common.postal_code')], |
64
|
|
|
'timezone' => ['title' => trans('cortex/statistics::common.timezone')], |
65
|
|
|
'city' => ['title' => trans('cortex/statistics::common.city')], |
66
|
|
|
'count' => ['title' => trans('cortex/statistics::common.count')], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: