关于lavarel:ModStart快速CRUD

36次阅读

共计 2634 个字符,预计需要花费 7 分钟才能阅读完成。

疾速 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;

上面的代码能够生成表 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('新闻治理');
    }
}

字段反对

显示 display

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

单行文本 text

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

多选 checkbox

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

标签 tags

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

代码 code

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

树状组件 tree

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

类型 type

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

明码 password

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

单张图片 image

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

多张图片 images

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

多张图片(长期门路)imagesTemp

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

链接 link

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

开关 switch

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

多行文本 textarea

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

色彩 color

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

日期 date

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

日期工夫 datetime

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

工夫 time

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

单选 radio

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

下拉 select

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

富文本 richHtml

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

Markdown markdown

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

键值对列表 keyValueList

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

多值 values

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

HTML html

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

数字 number

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

百分比 percent

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

小数 decimal

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

货币 currency

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

ID id

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

验证码 captcha

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

临时文件 fileTemp

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

文件 file

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

视频 video

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

音频 audio

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

中国地区 areaChina

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

暗藏域 hidden

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

图标 icon

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

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

正文完
 0