|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
|
6
|
|
|
use Illuminate\Support\Facades\App; |
|
7
|
|
|
use App\Models\Lookup\SkillType; |
|
8
|
|
|
// Validation |
|
9
|
|
|
use App\Http\Requests\SkillCrudRequest as StoreRequest; |
|
10
|
|
|
use App\Http\Requests\SkillCrudRequest as UpdateRequest; |
|
11
|
|
|
|
|
12
|
|
|
class SkillCrudController extends CrudController |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Prepare the admin interface by setting the associated |
|
16
|
|
|
* model, setting the route, and adding custom columns/fields. |
|
17
|
|
|
* |
|
18
|
|
|
* @return void |
|
19
|
|
|
*/ |
|
20
|
1 |
|
public function setup() : void |
|
21
|
|
|
{ |
|
22
|
|
|
// Workaround for how the unique_translation validation |
|
23
|
|
|
// works in App\Http\Requests\SkillCrudRequest |
|
24
|
1 |
|
$locale = 'en'; |
|
25
|
1 |
|
if (null !== $this->request->input('locale')) { |
|
26
|
|
|
$locale = $this->request->input('locale'); |
|
27
|
|
|
} |
|
28
|
1 |
|
App::setLocale($locale); |
|
29
|
|
|
|
|
30
|
|
|
// Eloquent model to associate with this collection |
|
31
|
|
|
// of views and controller actions. |
|
32
|
1 |
|
$this->crud->setModel("App\Models\Skill"); |
|
33
|
|
|
// Custom backpack route. |
|
34
|
1 |
|
$this->crud->setRoute("admin/skill"); |
|
35
|
|
|
// Custom strings to display within the backpack UI, |
|
36
|
|
|
// things like Create Skill, Delete Skills, etc. |
|
37
|
1 |
|
$this->crud->setEntityNameStrings('Skill', 'Skills'); |
|
38
|
|
|
|
|
39
|
|
|
// Add custom columns to the Skill index view |
|
40
|
1 |
|
$this->crud->addColumn([ |
|
41
|
1 |
|
'name' => 'name', |
|
42
|
1 |
|
'type' => 'text', |
|
43
|
1 |
|
'label' => 'Name', |
|
44
|
|
|
'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void { |
|
45
|
|
|
$query->orWhere('name->' . $locale, 'like', "%$searchTerm%"); |
|
46
|
1 |
|
}, |
|
47
|
|
|
'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
|
48
|
|
|
return $query->orderBy('name->' . $locale, $columnDirection)->select('*'); |
|
49
|
1 |
|
} |
|
50
|
|
|
]); |
|
51
|
1 |
|
$this->crud->addColumn([ |
|
52
|
1 |
|
'name' => 'description', |
|
53
|
1 |
|
'type' => 'text', |
|
54
|
1 |
|
'label' => 'Description', |
|
55
|
|
|
'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void { |
|
56
|
|
|
$query->orWhere('description->' . $locale, 'like', "%$searchTerm%"); |
|
57
|
1 |
|
}, |
|
58
|
|
|
'orderable' => false, |
|
59
|
|
|
]); |
|
60
|
1 |
|
$this->crud->addColumn([ |
|
61
|
1 |
|
'name' => 'skill_type.name', |
|
62
|
1 |
|
'type' => 'text', |
|
63
|
1 |
|
'label' => 'Type', |
|
64
|
|
|
'orderable' => true, |
|
65
|
|
|
'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
|
66
|
|
|
return $query->orderBy('skill_type_id', $columnDirection)->select('*'); |
|
67
|
1 |
|
} |
|
68
|
|
|
]); |
|
69
|
|
|
|
|
70
|
|
|
// Add custom fields to the create/update views |
|
71
|
1 |
|
$this->crud->addField([ |
|
72
|
1 |
|
'name' => 'name', |
|
73
|
|
|
'type' => 'text', |
|
74
|
|
|
'label' => "Name", |
|
75
|
|
|
]); |
|
76
|
1 |
|
$this->crud->addField([ |
|
77
|
1 |
|
'name' => 'description', |
|
78
|
|
|
'type' => 'textarea', |
|
79
|
|
|
'label' => "Description" |
|
80
|
|
|
]); |
|
81
|
1 |
|
$this->crud->addField([ |
|
82
|
1 |
|
'name' => 'skill_type_id', |
|
83
|
1 |
|
'label' => "Type", |
|
84
|
1 |
|
'type' => 'select_from_array', |
|
85
|
1 |
|
'options' => SkillType::all()->pluck('name', 'id')->toArray(), |
|
86
|
|
|
'allow_null' => false, |
|
87
|
|
|
]); |
|
88
|
1 |
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Action for creating a new Skill in the database. |
|
92
|
|
|
* |
|
93
|
|
|
* @param SkillCrudRequest $request Incoming form request. |
|
94
|
|
|
* |
|
95
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
96
|
|
|
*/ |
|
97
|
|
|
public function store(StoreRequest $request) // phpcs:ignore |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
return parent::storeCrud(); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Action for creating a new Skill in the database. |
|
104
|
|
|
* |
|
105
|
|
|
* @param SkillCrudRequest $request Incoming form request. |
|
106
|
|
|
* |
|
107
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
108
|
|
|
*/ |
|
109
|
|
|
public function update(UpdateRequest $request) // phpcs:ignore |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
return parent::updateCrud(); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.