first commit
This commit is contained in:
187
app/Admin/Controllers/PolicyController.php
Normal file
187
app/Admin/Controllers/PolicyController.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Category;
|
||||
use App\Models\ChinaArea;
|
||||
use App\Models\Policy;
|
||||
use App\Models\Trade;
|
||||
use Encore\Admin\Controllers\HasResourceActions;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Layout\Content;
|
||||
use Encore\Admin\Show;
|
||||
|
||||
class PolicyController extends Controller
|
||||
{
|
||||
use HasResourceActions;
|
||||
|
||||
/**
|
||||
* Index interface.
|
||||
*
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function index(Content $content)
|
||||
{
|
||||
return $content
|
||||
->header('资讯管理')
|
||||
->description('列表')
|
||||
->body($this->grid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Show interface.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function show($id, Content $content)
|
||||
{
|
||||
return $content
|
||||
->header('资讯管理')
|
||||
->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('资讯管理')
|
||||
->description('创建')
|
||||
->body($this->form());
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new Policy);
|
||||
|
||||
$grid->id('ID');
|
||||
// $grid->column('类型')->display(function () {
|
||||
// return $this->type == 'policy' ? '政策' : '解读';
|
||||
// });
|
||||
$grid->title('标题');
|
||||
$grid->no('文件号');
|
||||
$grid->category()->title('所属部门');
|
||||
// $grid->trade()->title('所属行业');
|
||||
|
||||
$grid->trades('所属行业')->display(function ($trades) {
|
||||
|
||||
$trades = array_map(function ($trade) {
|
||||
return "<span class='label label-success'>{$trade['title']}</span>";
|
||||
}, $trades);
|
||||
|
||||
return join(' ', $trades);
|
||||
});
|
||||
|
||||
$grid->areas('实行地区')->display(function ($areas) {
|
||||
|
||||
$areas = array_map(function ($area) {
|
||||
return "<span class='label label-success'>{$area['name']}</span>";
|
||||
}, $areas);
|
||||
|
||||
return join(' ', $areas);
|
||||
});
|
||||
|
||||
$grid->cover('标题图')->image('', 60, 60);
|
||||
$grid->status('状态')->switch();
|
||||
$grid->order('排序');
|
||||
$grid->begined_at('发布时间');
|
||||
// $grid->ended_at('结束时间');
|
||||
|
||||
$grid->filter(function ($filter) {
|
||||
|
||||
// 去掉默认的id过滤器
|
||||
$filter->disableIdFilter();
|
||||
// 在这里添加字段过滤器
|
||||
$filter->like('title', '标题');
|
||||
});
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
$show = new Show(Policy::findOrFail($id));
|
||||
|
||||
$show->id('ID');
|
||||
$show->title('标题');
|
||||
$show->description('简介');
|
||||
$show->cover('标题图')->image('', 60, 60);
|
||||
$show->content('详情');
|
||||
$show->status('状态')->using(['1' => '正常', '0' => '关闭']);
|
||||
$show->order('排序');
|
||||
$show->clicks('浏览量');
|
||||
$show->begined_at('发布时间');
|
||||
// $show->ended_at('结束时间');
|
||||
|
||||
return $show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new Policy);
|
||||
|
||||
$form->text('title', '标题')->rules('required');
|
||||
$form->text('no', '文件号')->rules('required');
|
||||
|
||||
$form->select('category_id', '所属部门')->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, ''))->rules('required');
|
||||
|
||||
// $form->multipleSelect('trade_id', '所属行业')->options(Trade::selectOptions(function ($model) {
|
||||
// return $model->where('status', 1);
|
||||
// }, ''))->rules('required');
|
||||
|
||||
$form->multipleSelect('trades', '所属行业')->options(Trade::where('status', 1)->pluck('title', 'id'), null)->rules('required');
|
||||
$form->multipleSelect('areas', '区域')->options(ChinaArea::where('parent_id', 9)->Orwhere('id', 9)->pluck('name', 'id'), null)->rules('required');
|
||||
// $form->datetimeRange('begined_at', 'ended_at', '生效时间')->rules('required');
|
||||
$form->datetime('begined_at', '发布时间')->rules('required');
|
||||
// $form->textarea('description', '简介');
|
||||
$form->image('cover', '标题图');
|
||||
$form->editor('content', '详情')->rules('required', ['required' => '详情不能为空']);
|
||||
$form->switch('status', '状态')->default(1);
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->number('clicks', '浏览量')->default(0);
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user