ExampleForm.php
2.9 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 管理端表单 trait层:渲染生成 分类 form 表单
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Admin\Forms
* @package App\Admin\Forms
* @author Richer <yangzi1028@163.com>
* @date 2020年11月13日 01:26:09
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Admin\Forms;
use App\Models\Example;
use Encore\Admin\Form;
/**
* Trait ExampleForm.
*
* @category App\Admin\Forms
* @package App\Admin\Forms
* @author Richer <yangzi1028@163.com>
* @date 2020年11月13日 01:26:09
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
trait ExampleForm
{
/**
* 渲染表单字段
*
* @param Int $id 用户id
*
* @return void
*/
public function renderFormFields($id)
{
// Text
$this->generateFormTextField($this->form, 'name', '标题', 255, true)
->creationRules(['required', "unique:examples"]);
// Single Image
$this->generateFormSingleImageField($this->form, 'image', '封面', true);
// Multiple Image
$this->generateFormMultipleImageField($this->form, 'images', '图片');
// Video
$this->generateFormVideoField($this->form, 'video', '视频');
// Select
$this->generateFormSingleSelectField($this->form, 'classify', '分类', Example::CLASSIFY_OPTIONS, true, 2);
// Multiple Select
$this->generateFormMultipleSelectField($this->form, 'tag', '标签', Example::TAG_OPTIONS, false, 2);
// Radio
$this->generateFormRadioField($this->form, 'gender', '性别', Example::GENDER_OPTIONS);
// Currency
$this->generateFormCurrencyField($this->form, 'money', '金额', true, 2);
// Slider
$this->generateFormSliderField($this->form, 'rate', '比例', true);
// Checkbox
$this->generateFormCheckboxField($this->form, 'type', '类型', Example::TYPE_OPTIONS);
// Switch
$this->generateFormSwitchField($this->form, 'status', '是否显示', Example::IS_SHOW_OPTIONS);
// Textarea
$this->generateFormTextAreaField($this->form, 'description', '描述');
// Editor
$this->generateFormRichTextField($this->form, 'content', '内容');
// Number
$this->generateFormNumberField($this->form, 'sort', '排序', false, 2, '0');
}
protected function submitted()
{
$this->form->submitted(
function (Form $form) {
//...
//dd(request()->all());
}
);
}
}