1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
6
|
|
|
// Validation. |
7
|
|
|
use App\Http\Requests\DepartmentCrudRequest as StoreRequest; |
8
|
|
|
use App\Http\Requests\DepartmentCrudRequest as UpdateRequest; |
9
|
|
|
|
10
|
|
|
class DepartmentCrudController extends CrudController |
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
|
2 |
|
public function setup() : void |
19
|
|
|
{ |
20
|
|
|
// Eloquent model to associate with this collection of views and controller actions. |
21
|
2 |
|
$this->crud->setModel('App\Models\Lookup\Department'); |
22
|
|
|
// Custom backpack route. |
23
|
2 |
|
$this->crud->setRoute('admin/department'); |
24
|
|
|
// Custom strings to display within the backpack UI. |
25
|
2 |
|
$this->crud->setEntityNameStrings('department', 'departments'); |
26
|
|
|
|
27
|
|
|
// Add custom columns to the Department index view. |
28
|
2 |
|
$this->crud->addColumn([ |
29
|
2 |
|
'name' => 'name', |
30
|
|
|
'type' => 'text', |
31
|
|
|
'label' => 'Name', |
32
|
|
|
]); |
33
|
|
|
|
34
|
2 |
|
$this->crud->addColumn([ |
35
|
2 |
|
'name' => 'impact', |
36
|
|
|
'type' => 'text', |
37
|
|
|
'label' => 'Impact', |
38
|
|
|
'orderable' => false, |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
// Add custom fields to the create/update views. |
42
|
2 |
|
$this->crud->addField([ |
43
|
2 |
|
'name' => 'name', |
44
|
|
|
'type' => 'text', |
45
|
|
|
'label' => 'Name', |
46
|
|
|
]); |
47
|
|
|
|
48
|
2 |
|
$this->crud->addField([ |
49
|
2 |
|
'name' => 'impact', |
50
|
|
|
'type' => 'textarea', |
51
|
|
|
'label' => 'Impact', |
52
|
|
|
]); |
53
|
2 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Action for creating a new department in the database. |
57
|
|
|
* |
58
|
|
|
* @param \App\Http\Requests\DepartmentCrudRequest $request Incoming form request. |
59
|
|
|
* @return \Illuminate\Http\RedirectResponse |
60
|
|
|
*/ |
61
|
|
|
public function store(StoreRequest $request) // phpcs:ignore |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
return parent::storeCrud(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Action for updating an existing department in the database. |
68
|
|
|
* |
69
|
|
|
* @param \App\Http\Requests\DepartmentCrudRequest $request Incoming form request. |
70
|
|
|
* @return \Illuminate\Http\RedirectResponse |
71
|
|
|
*/ |
72
|
|
|
public function update(UpdateRequest $request) // phpcs:ignore |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
return parent::updateCrud(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.