|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Auth\DataTables\Adminarea; |
|
6
|
|
|
|
|
7
|
|
|
use Cortex\Auth\Models\Admin; |
|
8
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
9
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
|
10
|
|
|
use Cortex\Auth\Transformers\Adminarea\AdminTransformer; |
|
11
|
|
|
|
|
12
|
|
|
class AdminsDataTable extends AbstractDataTable |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* {@inheritdoc} |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $model = Admin::class; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $transformer = AdminTransformer::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
|
|
|
->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1') |
|
48
|
|
|
->make(true); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get columns. |
|
53
|
|
|
* |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function getColumns(): array |
|
57
|
|
|
{ |
|
58
|
|
|
$link = config('cortex.foundation.route.locale_prefix') |
|
59
|
|
|
? '"<a href=\""+routes.route(\'adminarea.admins.edit\', {admin: full.id, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"' |
|
60
|
|
|
: '"<a href=\""+routes.route(\'adminarea.admins.edit\', {admin: full.id})+"\">"+data+"</a>"'; |
|
61
|
|
|
|
|
62
|
|
|
return [ |
|
63
|
|
|
'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], |
|
64
|
|
|
'given_name' => ['title' => trans('cortex/auth::common.given_name')], |
|
65
|
|
|
'family_name' => ['title' => trans('cortex/auth::common.family_name')], |
|
66
|
|
|
'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>") : "")'], |
|
67
|
|
|
'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>") : "")'], |
|
68
|
|
|
'country_code' => ['title' => trans('cortex/auth::common.country'), 'render' => 'full.country_emoji+" "+data'], |
|
69
|
|
|
'language_code' => ['title' => trans('cortex/auth::common.language'), 'visible' => false], |
|
70
|
|
|
'title' => ['title' => trans('cortex/auth::common.title'), 'visible' => false], |
|
71
|
|
|
'organization' => ['title' => trans('cortex/auth::common.organization'), 'visible' => false], |
|
72
|
|
|
'birthday' => ['title' => trans('cortex/auth::common.birthday'), 'visible' => false], |
|
73
|
|
|
'gender' => ['title' => trans('cortex/auth::common.gender'), 'visible' => false], |
|
74
|
|
|
'last_activity' => ['title' => trans('cortex/auth::common.last_activity'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')", 'visible' => false], |
|
75
|
|
|
'created_at' => ['title' => trans('cortex/auth::common.created_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
|
76
|
|
|
'updated_at' => ['title' => trans('cortex/auth::common.updated_at'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"], |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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: