|
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
|
1 |
|
* |
|
17
|
|
|
* @return void |
|
18
|
1 |
|
*/ |
|
19
|
1 |
|
public function setup() : void |
|
20
|
1 |
|
{ |
|
21
|
|
|
$this->crud->setModel('App\Models\User'); |
|
22
|
1 |
|
$this->crud->setRoute('admin/user'); |
|
23
|
1 |
|
$this->crud->setEntityNameStrings('user', 'users'); |
|
24
|
|
|
} |
|
25
|
1 |
|
|
|
26
|
1 |
|
public function setupListOperation() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->crud->addColumn([ |
|
29
|
|
|
'name' => 'id', |
|
30
|
1 |
|
'type' => 'number', |
|
31
|
1 |
|
'label' => 'ID' |
|
32
|
|
|
]); |
|
33
|
|
|
$this->crud->addColumn([ |
|
34
|
|
|
'name' => 'first_name', |
|
35
|
1 |
|
'type' => 'text', |
|
36
|
1 |
|
'label' => 'First Name' |
|
37
|
|
|
]); |
|
38
|
|
|
$this->crud->addColumn([ |
|
39
|
|
|
'name' => 'last_name', |
|
40
|
1 |
|
'type' => 'text', |
|
41
|
1 |
|
'label' => 'Last Name' |
|
42
|
|
|
]); |
|
43
|
|
|
$this->crud->addColumn([ |
|
44
|
|
|
'name' => 'user_role.name', |
|
45
|
|
|
'type' => 'text', |
|
46
|
1 |
|
'key' => 'user_role_name', |
|
47
|
1 |
|
'label' => 'Role' |
|
48
|
|
|
]); |
|
49
|
|
|
$this->crud->addColumn([ |
|
50
|
|
|
'name' => 'email', |
|
51
|
1 |
|
'type' => 'text', |
|
52
|
|
|
'label' => 'Email' |
|
53
|
|
|
]); |
|
54
|
1 |
|
$this->crud->addColumn([ |
|
55
|
|
|
'name' => 'gov_email', |
|
56
|
1 |
|
'type' => 'text', |
|
57
|
1 |
|
'label' => 'Government Email' |
|
58
|
|
|
]); |
|
59
|
|
|
$this->crud->addColumn([ |
|
60
|
|
|
'name' => 'not_in_gov', |
|
61
|
|
|
'type' => 'check', |
|
62
|
|
|
'label' => 'In Government' |
|
63
|
|
|
]); |
|
64
|
1 |
|
$this->crud->addColumn([ |
|
65
|
1 |
|
'name' => 'is_priority', |
|
66
|
|
|
'type' => 'check', |
|
67
|
|
|
'label' => 'Priority' |
|
68
|
|
|
]); |
|
69
|
|
|
$this->crud->addFilter([ |
|
70
|
|
|
'name' => 'user_role', |
|
71
|
|
|
'type' => 'select2', |
|
72
|
1 |
|
'label' => 'Role' |
|
73
|
1 |
|
], function () { |
|
74
|
|
|
return UserRole::all()->keyBy('id')->pluck('name', 'id')->toArray(); |
|
75
|
|
|
}, function ($value) : void { |
|
76
|
|
|
$this->crud->addClause('where', 'user_role_id', $value); |
|
77
|
1 |
|
}); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function setupUpdateOperation() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->crud->addField([ |
|
83
|
|
|
'name' => 'name', |
|
84
|
|
|
'label' => 'Name', |
|
85
|
|
|
'type' => 'text', |
|
86
|
|
|
'attributes' => [ |
|
87
|
|
|
'readonly'=>'readonly' |
|
88
|
|
|
] |
|
89
|
|
|
]); |
|
90
|
|
|
$this->crud->addField([ |
|
91
|
|
|
'label' => 'Role', |
|
92
|
|
|
'type' => 'select', |
|
93
|
|
|
'name' => 'user_role_id', // The db column for the foreign key. |
|
94
|
|
|
'entity' => 'user_role', // The method that defines the relationship in your Model. |
|
95
|
|
|
'attribute' => 'name', // Foreign key attribute that is shown to user. |
|
96
|
|
|
'model' => 'App\Models\UserRole' // Foreign key model. |
|
97
|
|
|
]); |
|
98
|
|
|
$this->crud->addField([ |
|
99
|
|
|
'name' => 'is_priority', |
|
100
|
|
|
'type' => 'checkbox', |
|
101
|
|
|
'label' => 'Priority' |
|
102
|
|
|
]); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|