|
2 | 2 |
|
3 | 3 | namespace Encore\Admin\Config; |
4 | 4 |
|
5 | | -use Encore\Admin\Controllers\ModelForm; |
| 5 | +use Encore\Admin\Controllers\HasResourceActions; |
6 | 6 | use Encore\Admin\Facades\Admin; |
7 | 7 | use Encore\Admin\Form; |
8 | 8 | use Encore\Admin\Grid; |
9 | 9 | use Encore\Admin\Layout\Content; |
| 10 | +use Encore\Admin\Show; |
10 | 11 |
|
11 | 12 | class ConfigController |
12 | 13 | { |
13 | | - use ModelForm; |
| 14 | + use HasResourceActions; |
14 | 15 |
|
15 | 16 | /** |
16 | 17 | * Index interface. |
17 | 18 | * |
18 | 19 | * @return Content |
19 | 20 | */ |
20 | | - public function index() |
| 21 | + public function index(Content $content) |
21 | 22 | { |
22 | | - return Admin::content(function (Content $content) { |
23 | | - $content->header('Config'); |
24 | | - $content->description('Config list..'); |
25 | | - |
26 | | - $content->body($this->grid()); |
27 | | - }); |
| 23 | + return $content |
| 24 | + ->header('Config') |
| 25 | + ->description('list') |
| 26 | + ->body($this->grid()); |
28 | 27 | } |
29 | 28 |
|
30 | 29 | /** |
31 | 30 | * Edit interface. |
32 | 31 | * |
33 | | - * @param $id |
| 32 | + * @param integer $id |
| 33 | + * @param Content $content |
34 | 34 | * |
35 | 35 | * @return Content |
36 | 36 | */ |
37 | | - public function edit($id) |
| 37 | + public function edit($id, Content $content) |
38 | 38 | { |
39 | | - return Admin::content(function (Content $content) use ($id) { |
40 | | - $content->header('header'); |
41 | | - $content->description('description'); |
42 | | - |
43 | | - $content->body($this->form()->edit($id)); |
44 | | - }); |
| 39 | + return $content |
| 40 | + ->header('Config') |
| 41 | + ->description('edit') |
| 42 | + ->body($this->form()->edit($id)); |
45 | 43 | } |
46 | 44 |
|
47 | 45 | /** |
48 | 46 | * Create interface. |
49 | 47 | * |
| 48 | + * @param Content $content |
| 49 | + * |
50 | 50 | * @return Content |
51 | 51 | */ |
52 | | - public function create() |
| 52 | + public function create(Content $content) |
53 | 53 | { |
54 | | - return Admin::content(function (Content $content) { |
55 | | - $content->header('header'); |
56 | | - $content->description('description'); |
| 54 | + return $content |
| 55 | + ->header('Config') |
| 56 | + ->description('create') |
| 57 | + ->body($this->form()); |
| 58 | + } |
57 | 59 |
|
58 | | - $content->body($this->form()); |
59 | | - }); |
| 60 | + public function show($id, Content $content) |
| 61 | + { |
| 62 | + return $content |
| 63 | + ->header('Config') |
| 64 | + ->description('detail') |
| 65 | + ->body(Admin::show(ConfigModel::findOrFail($id), function (Show $show) { |
| 66 | + |
| 67 | + $show->id(); |
| 68 | + $show->name(); |
| 69 | + $show->value(); |
| 70 | + $show->description(); |
| 71 | + $show->created_at(); |
| 72 | + $show->updated_at(); |
| 73 | + |
| 74 | + })); |
60 | 75 | } |
61 | 76 |
|
62 | 77 | public function grid() |
63 | 78 | { |
64 | | - return Admin::grid(ConfigModel::class, function (Grid $grid) { |
65 | | - $grid->id('ID')->sortable(); |
66 | | - $grid->name()->display(function ($name) { |
67 | | - return "<a tabindex=\"0\" class=\"btn btn-xs btn-twitter\" role=\"button\" data-toggle=\"popover\" data-html=true title=\"Usage\" data-content=\"<code>config('$name');</code>\">$name</a>"; |
68 | | - }); |
69 | | - $grid->value(); |
70 | | - $grid->description(); |
71 | | - |
72 | | - $grid->created_at(); |
73 | | - $grid->updated_at(); |
74 | | - |
75 | | - $grid->filter(function ($filter) { |
76 | | - $filter->disableIdFilter(); |
77 | | - $filter->like('name'); |
78 | | - $filter->like('value'); |
79 | | - }); |
| 79 | + $grid = new Grid(new ConfigModel()); |
| 80 | + |
| 81 | + $grid->id('ID')->sortable(); |
| 82 | + $grid->name()->display(function ($name) { |
| 83 | + return "<a tabindex=\"0\" class=\"btn btn-xs btn-twitter\" role=\"button\" data-toggle=\"popover\" data-html=true title=\"Usage\" data-content=\"<code>config('$name');</code>\">$name</a>"; |
80 | 84 | }); |
| 85 | + $grid->value(); |
| 86 | + $grid->description(); |
| 87 | + |
| 88 | + $grid->created_at(); |
| 89 | + $grid->updated_at(); |
| 90 | + |
| 91 | + $grid->filter(function ($filter) { |
| 92 | + $filter->disableIdFilter(); |
| 93 | + $filter->like('name'); |
| 94 | + $filter->like('value'); |
| 95 | + }); |
| 96 | + |
| 97 | + return $grid; |
81 | 98 | } |
82 | 99 |
|
83 | 100 | public function form() |
84 | 101 | { |
85 | | - return Admin::form(ConfigModel::class, function (Form $form) { |
86 | | - $form->display('id', 'ID'); |
87 | | - $form->text('name')->rules('required'); |
88 | | - $form->textarea('value')->rules('required'); |
89 | | - $form->textarea('description'); |
90 | | - |
91 | | - $form->display('created_at'); |
92 | | - $form->display('updated_at'); |
93 | | - }); |
| 102 | + $form = new Form(new ConfigModel()); |
| 103 | + |
| 104 | + $form->display('id', 'ID'); |
| 105 | + $form->text('name')->rules('required'); |
| 106 | + $form->textarea('value')->rules('required'); |
| 107 | + $form->textarea('description'); |
| 108 | + |
| 109 | + $form->display('created_at'); |
| 110 | + $form->display('updated_at'); |
| 111 | + |
| 112 | + return $form; |
94 | 113 | } |
95 | 114 | } |
0 commit comments