Skip to content

Commit 07f31b4

Browse files
committed
refactor
1 parent d16a142 commit 07f31b4

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

src/Scaffold/stubs/controller.stub

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,89 +3,73 @@
33
namespace DummyNamespace;
44

55
use DummyModelNamespace;
6-
6+
use App\Http\Controllers\Controller;
7+
use Encore\Admin\Controllers\HasResourceActions;
78
use Encore\Admin\Form;
89
use Encore\Admin\Grid;
9-
use Encore\Admin\Facades\Admin;
1010
use Encore\Admin\Layout\Content;
11-
use App\Http\Controllers\Controller;
12-
use Encore\Admin\Controllers\ModelForm;
1311
use Encore\Admin\Show;
1412

1513
class DummyClass extends Controller
1614
{
17-
use ModelForm;
15+
use HasResourceActions;
1816

1917
/**
2018
* Index interface.
2119
*
20+
* @param Content $content
2221
* @return Content
2322
*/
24-
public function index()
23+
public function index(Content $content)
2524
{
26-
return Admin::content(function (Content $content) {
27-
28-
$content->header('header');
29-
$content->description('description');
30-
31-
$content->body($this->grid());
32-
});
25+
return $content
26+
->header('Index')
27+
->description('description')
28+
->body($this->grid());
3329
}
3430

3531
/**
3632
* Show interface.
3733
*
38-
* @param mixed $id
34+
* @param mixed $id
3935
* @param Content $content
40-
*
4136
* @return Content
4237
*/
43-
public function show($id)
38+
public function show($id, Content $content)
4439
{
45-
return Admin::content(function (Content $content) use ($id) {
46-
47-
$content->header('Header');
48-
$content->description('Description');
49-
50-
$content->body(Admin::show(DummyModel::findOrFail($id), function (Show $show) {
51-
52-
$show->id('ID');
53-
54-
}));
55-
});
40+
return $content
41+
->header('Detail')
42+
->description('description')
43+
->body($this->detail($id));
5644
}
5745

5846
/**
5947
* Edit interface.
6048
*
61-
* @param $id
49+
* @param mixed $id
50+
* @param Content $content
6251
* @return Content
6352
*/
64-
public function edit($id)
53+
public function edit($id, Content $content)
6554
{
66-
return Admin::content(function (Content $content) use ($id) {
67-
68-
$content->header('header');
69-
$content->description('description');
70-
71-
$content->body($this->form()->edit($id));
72-
});
55+
return $content
56+
->header('Edit')
57+
->description('description')
58+
->body($this->form()->edit($id));
7359
}
7460

7561
/**
7662
* Create interface.
7763
*
64+
* @param Content $content
7865
* @return Content
7966
*/
80-
public function create()
67+
public function create(Content $content)
8168
{
82-
return Admin::content(function (Content $content) {
83-
84-
$content->header('header');
85-
$content->description('description');
86-
87-
$content->body($this->form());
88-
});
69+
return $content
70+
->header('Create')
71+
->description('description')
72+
->body($this->form());
8973
}
9074

9175
/**
@@ -95,13 +79,30 @@ class DummyClass extends Controller
9579
*/
9680
protected function grid()
9781
{
98-
return Admin::grid(DummyModel::class, function (Grid $grid) {
82+
$grid = new Grid(new DummyModel);
83+
84+
$grid->id('ID');
85+
$grid->created_at('Created at');
86+
$grid->updated_at('Updated at');
87+
88+
return $grid;
89+
}
90+
91+
/**
92+
* Make a show builder.
93+
*
94+
* @param mixed $id
95+
* @return Show
96+
*/
97+
protected function detail($id)
98+
{
99+
$show = new Show(DummyModel::findOrFail($id));
99100

100-
$grid->id('ID')->sortable();
101+
$show->id('ID');
102+
$show->created_at('Created at');
103+
$show->updated_at('Updated at');
101104

102-
$grid->created_at();
103-
$grid->updated_at();
104-
});
105+
return $show;
105106
}
106107

107108
/**
@@ -111,12 +112,12 @@ class DummyClass extends Controller
111112
*/
112113
protected function form()
113114
{
114-
return Admin::form(DummyModel::class, function (Form $form) {
115+
$form = new Form(new DummyModel);
115116

116-
$form->display('id', 'ID');
117+
$form->display('ID');
118+
$form->display('Created at');
119+
$form->display('Updated at');
117120

118-
$form->display('created_at', 'Created At');
119-
$form->display('updated_at', 'Updated At');
120-
});
121+
return $form;
121122
}
122123
}

0 commit comments

Comments
 (0)