|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\EvaluationTypeRequest as StoreRequest; |
|
6
|
|
|
// VALIDATION: change the requests to match your own file names if you need form validation |
|
7
|
|
|
use App\Models\EvaluationType; |
|
8
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
|
9
|
|
|
use Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation; |
|
10
|
|
|
use Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; |
|
11
|
|
|
use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
|
12
|
|
|
use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
|
13
|
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD; |
|
14
|
|
|
|
|
15
|
|
|
class EvaluationTypeCrudController extends CrudController |
|
16
|
|
|
{ |
|
17
|
|
|
use ListOperation; |
|
|
|
|
|
|
18
|
|
|
use CreateOperation {store as traitStore;} |
|
|
|
|
|
|
19
|
|
|
use UpdateOperation {update as traitUpdate;} |
|
|
|
|
|
|
20
|
|
|
use DeleteOperation; |
|
21
|
|
|
|
|
22
|
|
|
public function setup() |
|
23
|
|
|
{ |
|
24
|
|
|
CRUD::setModel(EvaluationType::class); |
|
25
|
|
|
CRUD::setRoute(config('backpack.base.route_prefix').'/evaluationtype'); |
|
26
|
|
|
CRUD::setEntityNameStrings(__('evaluation type'), __('evaluation types')); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function setupListOperation() |
|
30
|
|
|
{ |
|
31
|
|
|
CRUD::addColumn(['name' => 'name', 'label' => 'Name']); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function setupCreateOperation() |
|
35
|
|
|
{ |
|
36
|
|
|
CRUD::addField(['name' => 'name', 'label' => 'Name', 'type' => 'text']); |
|
37
|
|
|
|
|
38
|
|
|
CRUD::addField([ // Select2Multiple = n-n relationship (with pivot table) |
|
39
|
|
|
'label' => __('Grade Types'), |
|
40
|
|
|
'type' => 'select2_multiple', |
|
41
|
|
|
'name' => 'gradeTypes', // the method that defines the relationship in your Model |
|
42
|
|
|
|
|
43
|
|
|
// optional |
|
44
|
|
|
'entity' => 'gradeTypes', // the method that defines the relationship in your Model |
|
45
|
|
|
'model' => "App\Models\GradeType", // foreign key model |
|
46
|
|
|
'attribute' => 'complete_name', // foreign key attribute that is shown to user |
|
47
|
|
|
'pivot' => true, // on create&update, do you need to add/delete pivot table entries? |
|
48
|
|
|
'select_all' => true, // show Select All and Clear buttons? |
|
49
|
|
|
]); |
|
50
|
|
|
|
|
51
|
|
|
CRUD::addField([ // Select2Multiple = n-n relationship (with pivot table) |
|
52
|
|
|
'label' => __('Skills'), |
|
53
|
|
|
'type' => 'select2_multiple', |
|
54
|
|
|
'name' => 'skills', // the method that defines the relationship in your Model |
|
55
|
|
|
|
|
56
|
|
|
// optional |
|
57
|
|
|
'entity' => 'skills', // the method that defines the relationship in your Model |
|
58
|
|
|
'model' => "App\Models\Skills\Skill", // foreign key model |
|
59
|
|
|
'attribute' => 'complete_name', // foreign key attribute that is shown to user |
|
60
|
|
|
'pivot' => true, // on create&update, do you need to add/delete pivot table entries? |
|
61
|
|
|
'select_all' => true, // show Select All and Clear buttons? |
|
62
|
|
|
]); |
|
63
|
|
|
|
|
64
|
|
|
CRUD::setValidation(StoreRequest::class); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function setupUpdateOperation() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->setupCreateOperation(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function store() |
|
73
|
|
|
{ |
|
74
|
|
|
$value = $this->crud->getRequest()->input('name'); |
|
|
|
|
|
|
75
|
|
|
$response = $this->traitStore(); |
|
76
|
|
|
$entry = $this->crud->getCurrentEntry(); |
|
77
|
|
|
|
|
78
|
|
|
$this->overrideTranslations($entry, $value); |
|
79
|
|
|
|
|
80
|
|
|
return $response; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
private function overrideTranslations($entry, $value) { |
|
84
|
|
|
foreach (config('app.languages') as $i => $locale) { |
|
85
|
|
|
$entry->setTranslation('name', $locale, $value); |
|
86
|
|
|
} |
|
87
|
|
|
$entry->save(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function update() |
|
91
|
|
|
{ |
|
92
|
|
|
$value = $this->crud->getRequest()->input('name'); |
|
93
|
|
|
$response = $this->traitStore(); |
|
94
|
|
|
$entry = $this->crud->getCurrentEntry(); |
|
95
|
|
|
|
|
96
|
|
|
$this->overrideTranslations($entry, $value); |
|
97
|
|
|
|
|
98
|
|
|
return $response; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|