|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\UpdateResourceCrudRequest; |
|
6
|
|
|
use App\Http\Requests\StoreResourceCrudRequest; |
|
7
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
|
8
|
|
|
use Illuminate\Support\Facades\App; |
|
9
|
|
|
|
|
10
|
|
|
class ResourcesCrudController extends CrudController |
|
11
|
|
|
{ |
|
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
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; |
|
17
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Setup for the Resource CRUD panel. Everything here is applied on ALL operations. |
|
21
|
|
|
* |
|
22
|
|
|
* @return void |
|
23
|
|
|
*/ |
|
24
|
|
|
public function setup() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->crud->setModel('App\Models\Resource'); |
|
27
|
|
|
$this->crud->setRoute('admin/resource'); |
|
28
|
|
|
$this->crud->setEntityNameStrings('resource', 'resources'); |
|
29
|
|
|
|
|
30
|
|
|
$this->crud->operation(['create', 'update'], function () { |
|
31
|
|
|
$this->crud->addField([ |
|
32
|
|
|
'name' => 'name', |
|
33
|
|
|
'type' => 'text', |
|
34
|
|
|
'label' => 'Title', |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
|
|
$this->crud->addField([ |
|
38
|
|
|
'name' => 'file', |
|
39
|
|
|
'label' => 'File', |
|
40
|
|
|
'type' => 'upload', |
|
41
|
|
|
'upload' => true, |
|
42
|
|
|
]); |
|
43
|
|
|
}); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Setup list of resources. |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function setupListOperation() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->crud->removeButton('show'); |
|
54
|
|
|
|
|
55
|
|
|
$locale = 'en'; |
|
56
|
|
|
if (null !== $this->request->input('locale')) { |
|
57
|
|
|
$locale = $this->request->input('locale'); |
|
58
|
|
|
} |
|
59
|
|
|
App::setLocale($locale); |
|
60
|
|
|
|
|
61
|
|
|
$this->crud->addColumn([ |
|
62
|
|
|
'name' => 'id', |
|
63
|
|
|
'type' => 'text', |
|
64
|
|
|
'label' => 'ID', |
|
65
|
|
|
]); |
|
66
|
|
|
|
|
67
|
|
|
$this->crud->addColumn([ |
|
68
|
|
|
'name' => 'name', |
|
69
|
|
|
'type' => 'text', |
|
70
|
|
|
'label' => 'Title', |
|
71
|
|
|
'orderLogic' => function ($query, $column, $columnDirection) use ($locale) { |
|
72
|
|
|
return $query->orderBy('name->' . $locale, $columnDirection)->select('*'); |
|
73
|
|
|
}, |
|
74
|
|
|
'searchLogic' => function ($query, $column, $searchTerm) use ($locale): void { |
|
75
|
|
|
$query->orWhere('name->' . $locale, 'ilike', "%$searchTerm%"); |
|
76
|
|
|
}, |
|
77
|
|
|
]); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Create resource operation. |
|
82
|
|
|
* |
|
83
|
|
|
* @return void |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function setupCreateOperation() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->crud->setValidation(StoreResourceCrudRequest::class); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Update resource operation. |
|
92
|
|
|
* |
|
93
|
|
|
* @return void |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function setupUpdateOperation() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->crud->setValidation(UpdateResourceCrudRequest::class); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|