提交代码
This commit is contained in:
104
app/Admin/Controllers/AdvertController.php
Normal file
104
app/Admin/Controllers/AdvertController.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Layout\Content;
|
||||
|
||||
class AdvertController extends AdminController
|
||||
{
|
||||
|
||||
/**
|
||||
* Index interface.
|
||||
*
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function index(Content $content)
|
||||
{
|
||||
return $content
|
||||
->header('轮播图管理')
|
||||
->description('列表')
|
||||
->body($this->grid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$channel_type = (new Advert)->channel_type;
|
||||
|
||||
$grid = new Grid(new Advert);
|
||||
|
||||
$grid->id('ID');
|
||||
$grid->column('频道')->display(function () {
|
||||
return $this->channel_text;
|
||||
});
|
||||
|
||||
$grid->cover('图片')->image('', 60, 60);
|
||||
$grid->url('地址');
|
||||
$grid->sort('排序');
|
||||
|
||||
$grid->filter(function ($filter) use ($channel_type) {
|
||||
// 去掉默认的id过滤器
|
||||
$filter->disableIdFilter();
|
||||
// 在这里添加字段过滤器
|
||||
$filter->equal('channel', '渠道')->select($channel_type);
|
||||
});
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$channel_type = (new Advert)->channel_type;
|
||||
$form = new Form(new Advert);
|
||||
|
||||
$form->select('channel', '频道')->options($channel_type)->rules('required', ['required' => '必须选择频道']);
|
||||
$form->text('url', '地址')->rules('required');
|
||||
$form->image('cover', '图片')->rules('required')->uniqueName();
|
||||
$form->number('sort', '排序')->default(1);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user