Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
z-song committed Sep 16, 2018
1 parent d16a142 commit 07f31b4
Showing 1 changed file with 55 additions and 54 deletions.
109 changes: 55 additions & 54 deletions src/Scaffold/stubs/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,73 @@
namespace DummyNamespace;

use DummyModelNamespace;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Show;

class DummyClass extends Controller
{
use ModelForm;
use HasResourceActions;

/**
* Index interface.
*
* @param Content $content
* @return Content
*/
public function index()
public function index(Content $content)
{
return Admin::content(function (Content $content) {

$content->header('header');
$content->description('description');

$content->body($this->grid());
});
return $content
->header('Index')
->description('description')
->body($this->grid());
}

/**
* Show interface.
*
* @param mixed $id
* @param mixed $id
* @param Content $content
*
* @return Content
*/
public function show($id)
public function show($id, Content $content)
{
return Admin::content(function (Content $content) use ($id) {

$content->header('Header');
$content->description('Description');

$content->body(Admin::show(DummyModel::findOrFail($id), function (Show $show) {

$show->id('ID');

}));
});
return $content
->header('Detail')
->description('description')
->body($this->detail($id));
}

/**
* Edit interface.
*
* @param $id
* @param mixed $id
* @param Content $content
* @return Content
*/
public function edit($id)
public function edit($id, Content $content)
{
return Admin::content(function (Content $content) use ($id) {

$content->header('header');
$content->description('description');

$content->body($this->form()->edit($id));
});
return $content
->header('Edit')
->description('description')
->body($this->form()->edit($id));
}

/**
* Create interface.
*
* @param Content $content
* @return Content
*/
public function create()
public function create(Content $content)
{
return Admin::content(function (Content $content) {

$content->header('header');
$content->description('description');

$content->body($this->form());
});
return $content
->header('Create')
->description('description')
->body($this->form());
}

/**
Expand All @@ -95,13 +79,30 @@ class DummyClass extends Controller
*/
protected function grid()
{
return Admin::grid(DummyModel::class, function (Grid $grid) {
$grid = new Grid(new DummyModel);

$grid->id('ID');
$grid->created_at('Created at');
$grid->updated_at('Updated at');

return $grid;
}

/**
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
$show = new Show(DummyModel::findOrFail($id));

$grid->id('ID')->sortable();
$show->id('ID');
$show->created_at('Created at');
$show->updated_at('Updated at');

$grid->created_at();
$grid->updated_at();
});
return $show;
}

/**
Expand All @@ -111,12 +112,12 @@ class DummyClass extends Controller
*/
protected function form()
{
return Admin::form(DummyModel::class, function (Form $form) {
$form = new Form(new DummyModel);

$form->display('id', 'ID');
$form->display('ID');
$form->display('Created at');
$form->display('Updated at');

$form->display('created_at', 'Created At');
$form->display('updated_at', 'Updated At');
});
return $form;
}
}

0 comments on commit 07f31b4

Please sign in to comment.