|
|
@ -0,0 +1,77 @@ |
|
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
namespace App\AdminAgent\Controllers; |
|
|
|
|
|
|
|
|
|
|
|
use App\AdminAgent\Repositories\Slide; |
|
|
|
|
|
use Dcat\Admin\Admin; |
|
|
|
|
|
use Dcat\Admin\Form; |
|
|
|
|
|
use Dcat\Admin\Grid; |
|
|
|
|
|
use Dcat\Admin\Show; |
|
|
|
|
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
|
|
|
|
|
|
|
|
|
|
class SlideController extends AdminController |
|
|
|
|
|
{ |
|
|
|
|
|
/** |
|
|
|
|
|
* Make a grid builder. |
|
|
|
|
|
* |
|
|
|
|
|
* @return Grid |
|
|
|
|
|
*/ |
|
|
|
|
|
protected function grid() |
|
|
|
|
|
{ |
|
|
|
|
|
return Grid::make(new Slide(), function (Grid $grid) { |
|
|
|
|
|
$grid->model()->where('agent_id', Admin::user()->id)->orderBy('sort'); |
|
|
|
|
|
|
|
|
|
|
|
$grid->column('id')->sortable(); |
|
|
|
|
|
$grid->column('title'); |
|
|
|
|
|
$grid->column('url')->image('', 60, 60); |
|
|
|
|
|
$grid->column('status')->switch(); |
|
|
|
|
|
$grid->column('sort')->editable()->sortable()->width(120); |
|
|
|
|
|
|
|
|
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
|
|
|
|
$filter->equal('id'); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Make a show builder. |
|
|
|
|
|
* |
|
|
|
|
|
* @param mixed $id |
|
|
|
|
|
* |
|
|
|
|
|
* @return Show |
|
|
|
|
|
*/ |
|
|
|
|
|
protected function detail($id) |
|
|
|
|
|
{ |
|
|
|
|
|
return Show::make($id, new Slide(), function (Show $show) { |
|
|
|
|
|
$show->field('id'); |
|
|
|
|
|
$show->field('title'); |
|
|
|
|
|
$show->field('url')->image('', 80, 80); |
|
|
|
|
|
$show->field('status')->using(['禁用', '启用']); |
|
|
|
|
|
$show->field('sort'); |
|
|
|
|
|
$show->field('created_at'); |
|
|
|
|
|
$show->field('updated_at'); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Make a form builder. |
|
|
|
|
|
* |
|
|
|
|
|
* @return Form |
|
|
|
|
|
*/ |
|
|
|
|
|
protected function form() |
|
|
|
|
|
{ |
|
|
|
|
|
return Form::make(new Slide(), function (Form $form) { |
|
|
|
|
|
$form->display('id'); |
|
|
|
|
|
$form->text('title'); |
|
|
|
|
|
$form->image('url')->required()->removable(false); |
|
|
|
|
|
$form->switch('status')->required(); |
|
|
|
|
|
$form->text('sort')->required(); |
|
|
|
|
|
})->saving(function (Form $form) { |
|
|
|
|
|
//处理特殊字段
|
|
|
|
|
|
$form->hidden(['agent_id']); |
|
|
|
|
|
$form->agent_id = Admin::user()->id; |
|
|
|
|
|
$form->status = $form->status ? 1 : 0; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |