快速CRUD

在一些基础的场合,Grid、Form、Detail 具有高度的相似,可以合并使用一个快速的 CRUD 工具。

基本使用

先来个例子,数据库中有 news

  1. CREATE TABLE `news` (
  2. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  3. `title` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  4. `cover` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
  5. `summary` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  6. `content` text,
  7. `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  8. `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  9. PRIMARY KEY (`id`)
  10. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

下面的代码可以生成表 news 的数据表格

  1. <?php
  2. namespace App\Admin\Controller;
  3. use Illuminate\Routing\Controller;
  4. use ModStart\Admin\Concern\HasAdminQuickCRUD;
  5. use ModStart\Admin\Layout\AdminCRUDBuilder;
  6. class NewsController extends Controller
  7. {
  8. use HasAdminQuickCRUD;
  9. protected function crud(AdminCRUDBuilder $builder)
  10. {
  11. $builder
  12. ->init('news')
  13. ->field(function ($builder) {
  14. $builder->id('id','ID');
  15. $builder->text('title', '名称');
  16. $builder->image('cover', '封面');
  17. $builder->textarea('summary', '摘要');
  18. $builder->richHtml('content', '内容');
  19. $builder->display('created_at', '创建时间');
  20. $builder->display('updated_at', '更新时间');
  21. })
  22. ->title('新闻管理');
  23. }
  24. }

字段支持

显示 display

  1. $builder->display('field','名称');

单行文本 text

  1. $builder->text('field', '名称');

多选 checkbox

  1. $builder->checkbox('field', '名称');

标签 tags

  1. $builder->tags('field', '名称');

代码 code

  1. $builder->code('field', '名称');

树状组件 tree

  1. $builder->tree('field', '名称');

类型 type

  1. $builder->type('field', '类型');

密码 password

  1. $builder->password('field', '类型');

单张图片 image

  1. $builder->image('field', '类型');

多张图片 images

  1. $builder->type('field', '类型');

多张图片(临时路径) imagesTemp

  1. $builder->type('field', '类型');
  1. $builder->link('field', '类型');

开关 switch

  1. $builder->switch('field', '类型');

多行文本 textarea

  1. $builder->textarea('field', '类型');

颜色 color

  1. $builder->color('field', '类型');

日期 date

  1. $builder->date('field', '类型');

日期时间 datetime

  1. $builder->datetime('field', '类型');

时间 time

  1. $builder->time('field', '类型');

单选 radio

  1. $builder->radio('field', '类型');

下拉 select

  1. $builder->select('field', '类型');

富文本 richHtml

  1. $builder->richHtml('field', '类型');

Markdown markdown

  1. $builder->markdown('field', '类型');

键值对列表 keyValueList

  1. $builder->keyValueList('field', '类型');

多值 values

  1. $builder->values('field', '类型');

HTML html

  1. $builder->html('field', '类型');

数字 number

  1. $builder->number('field', '类型');

百分比 percent

  1. $builder->percent('field', '类型');

小数 decimal

  1. $builder->decimal('field', '类型');

货币 currency

  1. $builder->currency('field', '类型');

ID id

  1. $builder->id('field', '类型');

验证码 captcha

  1. $builder->captcha('field', '类型');

临时文件 fileTemp

  1. $builder->fileTemp('field', '类型');

文件 file

  1. $builder->file('field', '类型');

视频 video

  1. $builder->video('field', '类型');

音频 audio

  1. $builder->audio('field', '类型');

中国地区 areaChina

  1. $builder->areaChina('field', '类型');

隐藏域 hidden

  1. $builder->hidden('field', '类型');

图标 icon

  1. $builder->icon('field', '类型');

更多内置组件请参照 ModStart\Support\Manager\FieldManager 中的定义