|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Encore\Admin\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Encore\Admin\Auth\Database\Menu; |
|
6
|
|
|
use Encore\Admin\Auth\Database\Role; |
|
7
|
|
|
use Encore\Admin\Facades\Admin; |
|
8
|
|
|
use Encore\Admin\Form; |
|
9
|
|
|
use Encore\Admin\Layout\Content; |
|
10
|
|
|
use Encore\Admin\Tree; |
|
11
|
|
|
use Encore\Admin\Widgets\Callout; |
|
12
|
|
|
use Illuminate\Routing\Controller; |
|
13
|
|
|
|
|
14
|
|
|
class MenuController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Index interface. |
|
18
|
|
|
* |
|
19
|
|
|
* @return Content |
|
20
|
|
|
*/ |
|
21
|
|
|
public function index() |
|
22
|
|
|
{ |
|
23
|
|
|
return Admin::content(function (Content $content) { |
|
24
|
|
|
$content->header(trans('admin::lang.menu')); |
|
|
|
|
|
|
25
|
|
|
$content->description(trans('admin::lang.list')); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$content->body($this->tree()); |
|
28
|
|
|
}); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Edit interface. |
|
33
|
|
|
* |
|
34
|
|
|
* @param $id |
|
35
|
|
|
* |
|
36
|
|
|
* @return Content |
|
37
|
|
|
*/ |
|
38
|
|
View Code Duplication |
public function edit($id) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
return Admin::content(function (Content $content) use ($id) { |
|
41
|
|
|
$content->header(trans('admin::lang.menu')); |
|
|
|
|
|
|
42
|
|
|
$content->description(trans('admin::lang.edit')); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$content->row($this->callout()); |
|
45
|
|
|
$content->row($this->form()->edit($id)); |
|
46
|
|
|
}); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create interface. |
|
51
|
|
|
* |
|
52
|
|
|
* @return Content |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function create() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
return Admin::content(function (Content $content) { |
|
57
|
|
|
$content->header(trans('admin::lang.menu')); |
|
|
|
|
|
|
58
|
|
|
$content->description(trans('admin::lang.create')); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$content->row($this->callout()); |
|
61
|
|
|
$content->row($this->form()); |
|
62
|
|
|
}); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param $id |
|
67
|
|
|
* |
|
68
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse |
|
69
|
|
|
*/ |
|
70
|
|
|
public function update($id) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->form()->update($id); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param $id |
|
77
|
|
|
* |
|
78
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
79
|
|
|
*/ |
|
80
|
|
|
public function destroy($id) |
|
81
|
|
|
{ |
|
82
|
|
|
if ($this->form()->destroy($id)) { |
|
83
|
|
|
return response()->json(['msg' => 'delete success!']); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
|
89
|
|
|
*/ |
|
90
|
|
|
public function store() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->form()->store(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Make a tree builder. |
|
97
|
|
|
* |
|
98
|
|
|
* @return Tree |
|
99
|
|
|
*/ |
|
100
|
|
|
public function tree() |
|
101
|
|
|
{ |
|
102
|
|
|
return Admin::tree(Menu::class); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Make a form builder. |
|
107
|
|
|
* |
|
108
|
|
|
* @return Form |
|
109
|
|
|
*/ |
|
110
|
|
|
public function form() |
|
111
|
|
|
{ |
|
112
|
|
|
return Admin::form(Menu::class, function (Form $form) { |
|
113
|
|
|
$form->display('id', 'ID'); |
|
114
|
|
|
|
|
115
|
|
|
$options = [0 => 'Root'] + Menu::buildSelectOptions(); |
|
116
|
|
|
|
|
117
|
|
|
$form->select('parent_id', trans('admin::lang.parent_id'))->options($options); |
|
118
|
|
|
$form->text('title', trans('admin::lang.title'))->rules('required'); |
|
119
|
|
|
$form->text('icon', trans('admin::lang.icon'))->default('fa-bars')->rules('required'); |
|
120
|
|
|
$form->text('uri', trans('admin::lang.uri')); |
|
121
|
|
|
$form->multipleSelect('roles', trans('admin::lang.roles'))->options(Role::all()->pluck('name', 'id')); |
|
122
|
|
|
|
|
123
|
|
|
$form->display('created_at', trans('admin::lang.created_at')); |
|
124
|
|
|
$form->display('updated_at', trans('admin::lang.updated_at')); |
|
125
|
|
|
}); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return Callout |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function callout() |
|
132
|
|
|
{ |
|
133
|
|
|
$text = 'For icons see <a href="http://fontawesome.io/icons/" target="_blank">http://fontawesome.io/icons/</a>'; |
|
134
|
|
|
|
|
135
|
|
|
return new Callout($text, 'Tips', 'info'); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.