# 快速CRUD

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

# 基本使用

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

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

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

<?php
namespace App\Admin\Controller;

use Illuminate\Routing\Controller;
use ModStart\Admin\Concern\HasAdminQuickCRUD;
use ModStart\Admin\Layout\AdminCRUDBuilder;

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

# 字段支持

# 显示 display

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

# 单行文本 text

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

# 多选 checkbox

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

# 标签 tags

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

# 代码 code

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

# 树状组件 tree

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

# 类型 type

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

# 密码 password

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

# 单张图片 image

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

# 多张图片 images

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

# 多张图片(临时路径) imagesTemp

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

# 开关 switch

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

# 多行文本 textarea

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

# 颜色 color

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

# 日期 date

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

# 日期时间 datetime

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

# 时间 time

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

# 单选 radio

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

# 下拉 select

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

# 富文本 richHtml

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

# Markdown markdown

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

# 键值对列表 keyValueList

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

# 多值 values

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

# HTML html

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

# 数字 number

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

# 百分比 percent

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

# 小数 decimal

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

# 货币 currency

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

# ID id

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

# 验证码 captcha

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

# 临时文件 fileTemp

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

# 文件 file

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

# 视频 video

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

# 音频 audio

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

# 中国地区 areaChina

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

# 隐藏域 hidden

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

# 图标 icon

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

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

Last Updated: 7 months ago