first commit
This commit is contained in:
178
app/Admin/Controllers/TradeController.php
Normal file
178
app/Admin/Controllers/TradeController.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Models\Trade;
|
||||
use Encore\Admin\Controllers\HasResourceActions;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Layout\Column;
|
||||
use Encore\Admin\Layout\Content;
|
||||
use Encore\Admin\Layout\Row;
|
||||
use Encore\Admin\Show;
|
||||
use Encore\Admin\Tree;
|
||||
use Encore\Admin\Widgets\Box;
|
||||
use Encore\Admin\Widgets\Form as WidgetsForm;
|
||||
|
||||
class TradeController extends Controller
|
||||
{
|
||||
use HasResourceActions;
|
||||
|
||||
/**
|
||||
* Index interface.
|
||||
*
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function index(Content $content)
|
||||
{
|
||||
return $content
|
||||
->header('行业')
|
||||
->row(function (Row $row) {
|
||||
$row->column(6, $this->treeView());
|
||||
|
||||
$row->column(6, function (Column $column) {
|
||||
$form = new WidgetsForm();
|
||||
|
||||
$form->select('parent_id', '上级行业')->options(Trade::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, '一级行业'));
|
||||
$form->text('title', '行业名称')->rules('required');
|
||||
$form->textarea('description', '行业简介')->rows(4)->rules('nullable');
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
|
||||
$form->action('/admin/trades');
|
||||
|
||||
$column->append((new Box('新增行业', $form))->style('success'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Encore\Admin\Tree
|
||||
*/
|
||||
protected function treeView()
|
||||
{
|
||||
return Trade::tree(function (Tree $tree) {
|
||||
$tree->disableCreate();
|
||||
$tree->branch(function ($branch) {
|
||||
if ($branch['status'] == 1) {
|
||||
$payload = "<i class='fa fa-eye text-primary'></i> ";
|
||||
} else {
|
||||
$payload = "<i class='fa fa-eye text-gray'></i> ";
|
||||
}
|
||||
$payload .= " [ID:{$branch['id']}] - ";
|
||||
$payload .= " <strong>{$branch['title']}</strong> ";
|
||||
$payload .= " <small style='color:#999'>{$branch['description']}</small>";
|
||||
|
||||
return $payload;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show interface.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function show($id, Content $content)
|
||||
{
|
||||
return $content
|
||||
->header('Detail')
|
||||
->description('description')
|
||||
->body($this->detail($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit interface.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function edit($id, Content $content)
|
||||
{
|
||||
return $content
|
||||
->header('编辑')
|
||||
->description('行业')
|
||||
->body($this->form()->edit($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create interface.
|
||||
*
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function create(Content $content)
|
||||
{
|
||||
return $content
|
||||
->header('Create')
|
||||
->description('description')
|
||||
->body($this->form());
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new Trade);
|
||||
|
||||
$grid->id('Id');
|
||||
$grid->title('行业名称');
|
||||
$grid->description('行业简介');
|
||||
$grid->order('排序');
|
||||
$grid->status('显示')->switch();
|
||||
$grid->created_at('创建时间');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
$show = new Show(Trade::findOrFail($id));
|
||||
|
||||
$show->id('Id');
|
||||
$show->parent_id('Parent id');
|
||||
$show->title('Title');
|
||||
$show->description('简介');
|
||||
$show->order('Order');
|
||||
$show->status('Status');
|
||||
$show->created_at('Created at');
|
||||
$show->updated_at('Updated at');
|
||||
|
||||
return $show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new Trade);
|
||||
|
||||
$form->select('parent_id', '上级行业')->options(Trade::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, '一级行业'));
|
||||
$form->text('title', '行业名称')->rules('required');
|
||||
$form->textarea('description', '行业简介')->rows(4)->rules('nullable');
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user