| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Module\GameItems\AdminControllers;
- use App\Module\GameItems\Models\ItemGroup;
- use App\Module\GameItems\Models\ItemGroupItem;
- use App\Module\GameItems\Models\ItemItem;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use UCore\DcatAdmin\AdminController;
- use Spatie\RouteAttributes\Attributes\Resource;
- #[Resource('game-items-group-items', names: 'dcat.admin.game-items-group-items')]
- class GroupItemController extends AdminController
- {
- /**
- * 标题
- *
- * @var string
- */
- protected $title = '物品组内容管理';
- /**
- * 列表页
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new ItemGroupItem(), function (Grid $grid) {
- $grid->column('id', 'ID')->sortable();
- $grid->column('group.name', '物品组');
- $grid->column('item.name', '物品');
- $grid->column('weight', '权重');
- $grid->column('created_at', '创建时间');
- $grid->column('updated_at', '更新时间');
- // 筛选
- $grid->filter(function ($filter) {
- $filter->equal('id', 'ID');
- $filter->equal('group_id', '物品组')->select(
- ItemGroup::pluck('name', 'id')
- );
- $filter->equal('item_id', '物品')->select(
- ItemItem::pluck('name', 'id')
- );
- });
- });
- }
- /**
- * 详情页
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make(ItemGroupItem::findOrFail($id), function (Show $show) {
- $show->field('id', 'ID');
- $show->field('group.name', '物品组');
- $show->field('item.name', '物品');
- $show->field('weight', '权重');
- $show->field('created_at', '创建时间');
- $show->field('updated_at', '更新时间');
- });
- }
- /**
- * 表单
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new ItemGroupItem(), function (Form $form) {
- $form->select('group_id', '物品组')
- ->options(ItemGroup::pluck('name', 'id'))
- ->required();
- $form->select('item_id', '物品')
- ->options(ItemItem::pluck('name', 'id'))
- ->required();
- $form->number('weight', '权重')
- ->default(1.0)
- ->min(0.001)
- ->step(0.001)
- ->required()
- ->help('权重越高,随机选择时概率越大');
- });
- }
- }
|