|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\Settings\app\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
|
6
|
|
|
// VALIDATION |
|
7
|
|
|
use Backpack\Settings\app\Http\Requests\SettingRequest as StoreRequest; |
|
8
|
|
|
use Backpack\Settings\app\Http\Requests\SettingRequest as UpdateRequest; |
|
9
|
|
|
|
|
10
|
|
|
class SettingCrudController extends CrudController |
|
11
|
|
|
{ |
|
12
|
|
|
public function __construct() |
|
13
|
|
|
{ |
|
14
|
|
|
parent::__construct(); |
|
15
|
|
|
|
|
16
|
|
|
$this->crud->setModel("Backpack\Settings\app\Models\Setting"); |
|
17
|
|
|
$this->crud->setEntityNameStrings('setting', 'settings'); |
|
18
|
|
|
$this->crud->setRoute('admin/setting'); |
|
19
|
|
|
$this->crud->denyAccess(['create', 'delete']); |
|
20
|
|
|
$this->crud->setColumns(['name', 'value', 'description']); |
|
21
|
|
|
$this->crud->addField([ |
|
22
|
|
|
'name' => 'name', |
|
23
|
|
|
'label' => 'Name', |
|
24
|
|
|
'type' => 'text', |
|
25
|
|
|
'disabled' => 'disabled', |
|
26
|
|
|
]); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Display all rows in the database for this entity. |
|
31
|
|
|
* This overwrites the default CrudController behaviour: |
|
32
|
|
|
* - instead of showing all entries, only show the "active" ones. |
|
33
|
|
|
* |
|
34
|
|
|
* @return Response |
|
35
|
|
|
*/ |
|
36
|
|
|
public function index() |
|
37
|
|
|
{ |
|
38
|
|
|
// if view_table_permission is false, abort |
|
39
|
|
|
$this->crud->hasAccessOrFail('list'); |
|
40
|
|
|
$this->crud->addClause('where', 'active', 1); // <---- this is where it's different from CrudController::index() |
|
41
|
|
|
|
|
42
|
|
|
$this->data['entries'] = $this->crud->getEntries(); |
|
43
|
|
|
$this->data['crud'] = $this->crud; |
|
44
|
|
|
$this->data['title'] = ucfirst($this->crud->entity_name_plural); |
|
45
|
|
|
|
|
46
|
|
|
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
47
|
|
|
return view('crud::list', $this->data); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function store(StoreRequest $request) |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
return parent::storeCrud(); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Show the form for editing the specified resource. |
|
58
|
|
|
* |
|
59
|
|
|
* @param int $id |
|
60
|
|
|
* |
|
61
|
|
|
* @return Response |
|
62
|
|
|
*/ |
|
63
|
|
|
public function edit($id) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->crud->hasAccessOrFail('update'); |
|
66
|
|
|
|
|
67
|
|
|
$this->data['entry'] = $this->crud->getEntry($id); |
|
68
|
|
|
$this->crud->addField((array)json_decode($this->data['entry']->field)); // <---- this is where it's different |
|
69
|
|
|
$this->data['crud'] = $this->crud; |
|
70
|
|
|
$this->data['fields'] = $this->crud->getUpdateFields($id); |
|
71
|
|
|
$this->data['title'] = trans('backpack::crud.edit').' '.$this->crud->entity_name; |
|
72
|
|
|
|
|
73
|
|
|
$this->data['id'] = $id; |
|
74
|
|
|
|
|
75
|
|
|
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
|
76
|
|
|
return view('crud::edit', $this->data); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
public function update(UpdateRequest $request) |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
return parent::updateCrud(); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.