1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
6
|
|
|
use App\Models\UserRole; |
7
|
|
|
|
8
|
|
|
class UserCrudController extends CrudController |
9
|
|
|
{ |
10
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
|
|
|
|
11
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Prepare the admin interface by setting the associated |
15
|
|
|
* model, setting the route, and adding custom columns/fields. |
16
|
|
|
* |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
public function setup() : void |
20
|
|
|
{ |
21
|
|
|
$this->crud->setModel('App\Models\User'); |
22
|
|
|
$this->crud->setRoute('admin/user'); |
23
|
|
|
$this->crud->setEntityNameStrings('user', 'users'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function setupListOperation() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$this->crud->addColumn([ |
29
|
|
|
'name' => 'name', |
30
|
|
|
'type' => 'text', |
31
|
|
|
'label' => 'Name' |
32
|
|
|
]); |
33
|
|
|
$this->crud->addColumn([ |
34
|
|
|
'name' => 'email', |
35
|
|
|
'type' => 'text', |
36
|
|
|
'label' => 'Email' |
37
|
|
|
]); |
38
|
|
|
$this->crud->addColumn([ |
39
|
|
|
'name' => 'user_role.name', |
40
|
|
|
'type' => 'text', |
41
|
|
|
'key' => 'user_role_name', |
42
|
|
|
'label' => 'Role' |
43
|
|
|
]); |
44
|
|
|
$this->crud->addColumn([ |
45
|
|
|
'name' => 'gov_email', |
46
|
|
|
'type' => 'text', |
47
|
|
|
'label' => 'Gov Email' |
48
|
|
|
]); |
49
|
|
|
$this->crud->addColumn([ |
50
|
|
|
'name' => 'not_in_gov', |
51
|
|
|
'type' => 'check', |
52
|
|
|
'label' => 'Not in Gov' |
53
|
|
|
]); |
54
|
|
|
$this->crud->addColumn([ |
55
|
|
|
'name' => 'is_priority', |
56
|
|
|
'type' => 'check', |
57
|
|
|
'label' => 'Priority' |
58
|
|
|
]); |
59
|
|
|
$this->crud->addFilter([ |
60
|
|
|
'name' => 'user_role', |
61
|
|
|
'type' => 'select2', |
62
|
|
|
'label' => 'Role' |
63
|
|
|
], function () { |
64
|
|
|
return UserRole::all()->keyBy('id')->pluck('name', 'id')->toArray(); |
65
|
|
|
}, function ($value) : void { |
66
|
|
|
$this->crud->addClause('where', 'user_role_id', $value); |
67
|
|
|
}); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function setupUpdateOperation() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$this->crud->addField([ |
73
|
|
|
'name' => 'name', |
74
|
|
|
'label' => 'Name', |
75
|
|
|
'type' => 'text', |
76
|
|
|
'attributes' => [ |
77
|
|
|
'readonly'=>'readonly' |
78
|
|
|
] |
79
|
|
|
]); |
80
|
|
|
$this->crud->addField([ |
81
|
|
|
'label' => 'Role', |
82
|
|
|
'type' => 'select', |
83
|
|
|
'name' => 'user_role_id', // The db column for the foreign key. |
84
|
|
|
'entity' => 'user_role', // The method that defines the relationship in your Model. |
85
|
|
|
'attribute' => 'name', // Foreign key attribute that is shown to user. |
86
|
|
|
'model' => 'App\Models\UserRole' // Foreign key model. |
87
|
|
|
]); |
88
|
|
|
$this->crud->addField([ |
89
|
|
|
'name' => 'is_priority', |
90
|
|
|
'type' => 'checkbox', |
91
|
|
|
'label' => 'Priority' |
92
|
|
|
]); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|