ExampleForm.php 2.9 KB
<?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());
            }
        );
    }
}