1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Http\Requests\UserRoleCrudRequest as UpdateRequest; |
6
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
7
|
|
|
use Illuminate\Support\Facades\App; |
8
|
|
|
|
9
|
|
|
class UserRoleCrudController extends CrudController |
10
|
|
|
{ |
11
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
12
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
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
|
|
|
public function setup() : void |
21
|
|
|
{ |
22
|
|
|
// Eloquent model to associate with this collection |
23
|
|
|
// of views and controller actions. |
24
|
|
|
$this->crud->setModel('App\Models\UserRole'); |
25
|
|
|
// Custom backpack route. |
26
|
|
|
$this->crud->setRoute('admin/user-role'); |
27
|
|
|
// Custom strings to display within the backpack UI, |
28
|
|
|
// things like Create User Role, Delete User Roles, etc. |
29
|
|
|
$this->crud->setEntityNameStrings('user role', 'user roles'); |
30
|
|
|
|
31
|
|
|
$this->crud->operation(['update'], function () { |
32
|
|
|
// Add custom fields to the update views. |
33
|
|
|
$this->crud->addField([ |
34
|
|
|
'name' => 'name', |
35
|
|
|
'type' => 'text', |
36
|
|
|
'label' => 'Name', |
37
|
|
|
]); |
38
|
|
|
}); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setupListOperation() |
42
|
|
|
{ |
43
|
|
|
// Workaround for how the unique_translation validation |
44
|
|
|
// works in App\Http\Requests\UserRoleCrudRequest. |
45
|
|
|
$locale = 'en'; |
46
|
|
|
if (null !== $this->request->input('locale')) { |
47
|
|
|
$locale = $this->request->input('locale'); |
48
|
|
|
} |
49
|
|
|
App::setLocale($locale); |
50
|
|
|
|
51
|
|
|
// Remove create/delete buttons. |
52
|
|
|
$this->crud->removeButton('delete'); |
53
|
|
|
$this->crud->removeButton('create'); |
54
|
|
|
|
55
|
|
|
// Add custom columns to the User Role index view. |
56
|
|
|
$this->crud->addColumn([ |
57
|
|
|
'name' => 'id', |
58
|
|
|
'type' => 'text', |
59
|
|
|
'label' => 'ID', |
60
|
|
|
'orderable' => true |
61
|
|
|
]); |
62
|
|
|
|
63
|
|
|
$this->crud->addColumn([ |
64
|
|
|
'name' => 'key', |
65
|
|
|
'type' => 'text', |
66
|
|
|
'label' => 'Key', |
67
|
|
|
'orderable' => true |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
$this->crud->addColumn([ |
71
|
|
|
'name' => 'name', |
72
|
|
|
'type' => 'text', |
73
|
|
|
'label' => 'Name', |
74
|
|
|
'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void { |
75
|
|
|
$query->orWhere('name->' . $locale, 'like', "%$searchTerm%"); |
76
|
|
|
}, |
77
|
|
|
'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
78
|
|
|
return $query->orderBy('name->' . $locale, $columnDirection)->select('*'); |
79
|
|
|
} |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setupUpdateOperation() |
84
|
|
|
{ |
85
|
|
|
$this->crud->setValidation(UpdateRequest::class); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|