1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Auth\DataTables\Adminarea; |
6
|
|
|
|
7
|
|
|
use Cortex\Auth\Models\Manager; |
8
|
|
|
use Illuminate\Database\Eloquent\Builder; |
9
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
10
|
|
|
use Cortex\Auth\Transformers\Adminarea\ManagerTransformer; |
11
|
|
|
|
12
|
|
|
class ManagersDataTable extends AbstractDataTable |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
protected $model = Manager::class; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected $transformer = ManagerTransformer::class; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Display ajax response. |
26
|
|
|
* |
27
|
|
|
* @return \Illuminate\Http\JsonResponse |
28
|
|
|
*/ |
29
|
|
|
public function ajax() |
30
|
|
|
{ |
31
|
|
|
return datatables($this->query()) |
|
|
|
|
32
|
|
|
->setTransformer(app($this->transformer)) |
33
|
|
|
->filterColumn('country_code', function (Builder $builder, $keyword) { |
34
|
|
|
$countryCode = collect(countries())->search(function ($country) use ($keyword) { |
35
|
|
|
return mb_strpos($country['name'], $keyword) !== false || mb_strpos($country['emoji'], $keyword) !== false; |
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
! $countryCode || $builder->where('country_code', $countryCode); |
39
|
|
|
}) |
40
|
|
|
->filterColumn('language_code', function (Builder $builder, $keyword) { |
41
|
|
|
$languageCode = collect(languages())->search(function ($language) use ($keyword) { |
42
|
|
|
return mb_strpos($language['name'], $keyword) !== false; |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
! $languageCode || $builder->where('language_code', $languageCode); |
46
|
|
|
}) |
47
|
|
|
->make(true); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get columns. |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
protected function getColumns(): array |
56
|
|
|
{ |
57
|
|
|
$link = config('cortex.foundation.route.locale_prefix') |
58
|
|
|
? '"<a href=\""+routes.route(\'adminarea.managers.edit\', {manager: full.id, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"' |
59
|
|
|
: '"<a href=\""+routes.route(\'adminarea.managers.edit\', {manager: full.id})+"\">"+data+"</a>"'; |
60
|
|
|
|
61
|
|
|
return [ |
62
|
|
|
'username' => ['title' => trans('cortex/auth::common.username'), 'render' => $link.'+(full.is_active ? " <i class=\"text-success fa fa-check\"></i>" : " <i class=\"text-danger fa fa-close\"></i>")', 'responsivePriority' => 0], |
63
|
|
|
'given_name' => ['title' => trans('cortex/auth::common.given_name')], |
64
|
|
|
'family_name' => ['title' => trans('cortex/auth::common.family_name')], |
65
|
|
|
'email' => ['title' => trans('cortex/auth::common.email'), 'render' => 'data+(data ? (full.email_verified_at ? " <i class=\"text-success fa fa-check\" title=\""+full.email_verified_at+"\"></i>" : " <i class=\"text-danger fa fa-close\"></i>") : "")'], |
66
|
|
|
'phone' => ['title' => trans('cortex/auth::common.phone'), 'render' => 'data+(data ? (full.phone_verified_at ? " <i class=\"text-success fa fa-check\" title=\""+full.phone_verified_at+"\"></i>" : " <i class=\"text-danger fa fa-close\"></i>") : "")'], |
67
|
|
|
'country_code' => ['title' => trans('cortex/auth::common.country'), 'render' => 'full.country_emoji+" "+data'], |
68
|
|
|
'language_code' => ['title' => trans('cortex/auth::common.language'), 'visible' => false], |
69
|
|
|
'title' => ['title' => trans('cortex/auth::common.title'), 'visible' => false], |
70
|
|
|
'organization' => ['title' => trans('cortex/auth::common.organization'), 'visible' => false], |
71
|
|
|
'birthday' => ['title' => trans('cortex/auth::common.birthday'), 'visible' => false], |
72
|
|
|
'gender' => ['title' => trans('cortex/auth::common.gender'), 'visible' => false], |
73
|
|
|
'last_activity' => ['title' => trans('cortex/auth::common.last_activity'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')", 'visible' => false], |
74
|
|
|
'created_at' => ['title' => trans('cortex/auth::common.created_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
75
|
|
|
'updated_at' => ['title' => trans('cortex/auth::common.updated_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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: