1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
// Validation. |
6
|
|
|
use App\Http\Requests\DepartmentCrudRequest as StoreRequest; |
7
|
|
|
use App\Http\Requests\DepartmentCrudRequest as UpdateRequest; |
8
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
9
|
|
|
use Illuminate\Support\Facades\App; |
10
|
|
|
|
11
|
|
|
class DepartmentCrudController extends CrudController |
12
|
|
|
{ |
13
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
|
|
|
|
14
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation; |
|
|
|
|
15
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Prepare the admin interface by setting the associated |
19
|
|
|
* model, setting the route, and adding custom columns/fields. |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
public function setup() : void |
24
|
|
|
{ |
25
|
|
|
// Eloquent model to associate with this collection of views and controller actions. |
26
|
|
|
$this->crud->setModel('App\Models\Lookup\Department'); |
27
|
|
|
// Custom backpack route. |
28
|
|
|
$this->crud->setRoute('admin/department'); |
29
|
|
|
// Custom strings to display within the backpack UI. |
30
|
|
|
$this->crud->setEntityNameStrings('department', 'departments'); |
31
|
|
|
|
32
|
|
|
$this->crud->operation(['create', 'update'], function () { |
33
|
|
|
$this->crud->addField([ |
34
|
|
|
'name' => 'name', |
35
|
|
|
'type' => 'text', |
36
|
|
|
'label' => 'Name', |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$this->crud->addField([ |
40
|
|
|
'name' => 'impact', |
41
|
|
|
'type' => 'textarea', |
42
|
|
|
'label' => 'Impact', |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
$this->crud->addField([ |
46
|
|
|
'name' => 'preference', |
47
|
|
|
'type' => 'textarea', |
48
|
|
|
'label' => 'Preference', |
49
|
|
|
]); |
50
|
|
|
}); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function setupListOperation() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
// Required for order logic. |
56
|
|
|
$locale = 'en'; |
57
|
|
|
if (null !== $this->request->input('locale')) { |
58
|
|
|
$locale = $this->request->input('locale'); |
59
|
|
|
} |
60
|
|
|
App::setLocale($locale); |
61
|
|
|
|
62
|
|
|
// Remove delete button. |
63
|
|
|
$this->crud->removeButton('delete'); |
64
|
|
|
|
65
|
|
|
// Add custom columns to the Department index view. |
66
|
|
|
$this->crud->addColumn([ |
67
|
|
|
'name' => 'id', |
68
|
|
|
'type' => 'text', |
69
|
|
|
'label' => 'ID', |
70
|
|
|
'orderable' => true, |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
$this->crud->addColumn([ |
74
|
|
|
'name' => 'name', |
75
|
|
|
'type' => 'text', |
76
|
|
|
'label' => 'Name', |
77
|
|
|
'orderable' => true, |
78
|
|
|
'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
79
|
|
|
return $query->orderBy('name->' . $locale, $columnDirection)->select('*'); |
80
|
|
|
} |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
$this->crud->addColumn([ |
84
|
|
|
'name' => 'impact', |
85
|
|
|
'type' => 'text', |
86
|
|
|
'label' => 'Impact', |
87
|
|
|
'orderable' => false, |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
$this->crud->addColumn([ |
91
|
|
|
'name' => 'preference', |
92
|
|
|
'type' => 'text', |
93
|
|
|
'label' => 'Preference', |
94
|
|
|
'orderable' => false, |
95
|
|
|
]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function setupCreateOperation() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$this->crud->setValidation(StoreRequest::class); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function setupUpdateOperation() |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$this->crud->setValidation(UpdateRequest::class); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|