1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
6
|
|
|
|
7
|
|
|
class ManagerCrudController extends CrudController |
8
|
|
|
{ |
9
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
10
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Prepare the admin interface by setting the associated |
14
|
|
|
* model, setting the route, and adding custom columns/fields. |
15
|
|
|
* |
16
|
|
|
* @return void |
17
|
|
|
*/ |
18
|
|
|
public function setup() : void |
19
|
|
|
{ |
20
|
|
|
$this->crud->setModel('App\Models\User'); |
21
|
|
|
$this->crud->setRoute('admin/manager'); |
22
|
|
|
$this->crud->setEntityNameStrings('manager', 'managers'); |
23
|
|
|
|
24
|
|
|
// Don't show 'basic' users. |
25
|
|
|
$this->crud->addClause('whereIn', 'user_role_id', [2, 3]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function setupListOperation() |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
$this->crud->addColumn([ |
32
|
|
|
'name' => 'manager.id', |
33
|
|
|
'key' => 'manager_id', |
34
|
|
|
'type' => 'number', |
35
|
|
|
'label' => 'ID' |
36
|
|
|
]); |
37
|
|
|
$this->crud->addColumn([ |
38
|
|
|
'name' => 'full_name', |
39
|
|
|
'key' => 'manager_name', |
40
|
|
|
'type' => 'text', |
41
|
|
|
'label' => 'Name' |
42
|
|
|
]); |
43
|
|
|
$this->crud->addColumn([ |
44
|
|
|
'name' => 'user_role.name', |
45
|
|
|
'type' => 'text', |
46
|
|
|
'key' => 'user_role_name', |
47
|
|
|
'label' => 'Role' |
48
|
|
|
]); |
49
|
|
|
$this->crud->addColumn([ |
50
|
|
|
'name' => 'email', |
51
|
|
|
'key' => 'manager_email', |
52
|
|
|
'type' => 'text', |
53
|
|
|
'label' => 'Email' |
54
|
|
|
]); |
55
|
|
|
$this->crud->addColumn([ |
56
|
|
|
'name' => 'gov_email', |
57
|
|
|
'key' => 'government_email', |
58
|
|
|
'type' => 'text', |
59
|
|
|
'label' => 'Government Email' |
60
|
|
|
]); |
61
|
|
|
$this->crud->addColumn([ |
62
|
|
|
'name' => 'manager.department.name', |
63
|
|
|
'key' => 'manager_department', |
64
|
|
|
'type' => 'text', |
65
|
|
|
'label' => 'Department', |
66
|
|
|
'limit' => 70 |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
// Add the custom blade button found in resources/views/vendor/backpack/crud/buttons/profile_edit.blade.php. |
70
|
|
|
$this->crud->addButtonFromView('line', 'create_job_poster', 'create_job_poster', 'beginning'); |
71
|
|
|
$this->crud->addButtonFromView('line', 'profile_edit', 'profile_edit', 'end'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function setupUpdateOperation() |
75
|
|
|
{ |
76
|
|
|
$this->crud->addField([ |
77
|
|
|
'name' => 'full_name', |
78
|
|
|
'label' => 'Name', |
79
|
|
|
'type' => 'text', |
80
|
|
|
'attributes' => [ |
81
|
|
|
'readonly'=>'readonly' |
82
|
|
|
] |
83
|
|
|
]); |
84
|
|
|
$this->crud->addField([ |
85
|
|
|
'label' => 'Department', |
86
|
|
|
'type' => 'select2', |
87
|
|
|
'name' => 'department_id', // The db column for the foreign key. |
88
|
|
|
'entity' => 'manager.department', // The method that defines the relationship in your Model. |
89
|
|
|
'attribute' => 'name', // Foreign key attribute that is shown to user. |
90
|
|
|
'model' => 'App\Models\Lookup\Department' // Foreign key model. |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|