moirei/fields 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

moirei/fields

Composer 安装命令:

composer require moirei/fields

包简介

A simple package for code-defined application inputs & fields.

README 文档

README

This package provides a simple solution for working with backend defined fields. Use cases:

  • Backend defined forms fields
  • Defined survey questionnaire with strict input types and valid values
  • Define configuration application settings options with default values
  • Fetch form data (including input type, validation rules, etc) from the backend for frontend display.

Notes

  • This package was inspired by Laravel Nova fields.
  • Field properties are aimed to be consistent with Vuetify form input component properties.
$field = Boolean::make('Enable notification')->default(false);

Installation

composer require moirei/fields

Usage

use MOIREI\Fields\Inputs\Field;
use MOIREI\Fields\Inputs\{Text, Number, Select, Radio, Textarea};
...

$survey_questions = [
    Text::make('Whats your name?', 'name')
        ->rules('max:24')
        ->placeholder('John Doe')
        ->toArray(),

    Number::make('How old are you?', 'age')
        ->min(18)
        ->toArray(),

    Select::make('Gender')
        ->options([
            'Fridge',
            'Bridge',
            [ 'text' => 'I prefer not to say', 'value' => 'other' ],
        ])
        ->default('other')
        ->toArray(),

    Radio::make('Can keep you data for future promos?', 'subscribe')
        ->trueValue('Yes plez')
        ->falseValue('No thanks')
        ->toArray(),

    Textarea::make('More about yourself?', 'more')
        ->rows(10)
        ->hint('In a few words. Feel free to elaborate on the above.')
        ->persistentHint()
        ->toArray(),
];

Validation

$field = Text::make('Whats your name?', 'name')
        ->rules('max:24')
        ->placeholder('John Doe');

$valid = $field->validate('James Bond');
// or assert and throw exception
$field->validate('James Bond', true)

Validate multiple values

$fields = [
    Text::make('Whats your name?', 'name')
        ->rules('max:24')
        ->placeholder('John Doe'),
    ...
];

$returnOnlyValidated = true;

$input = Field::validateInput($request->all(), $fields, $returnOnlyValidated)

Tests

composer test

统计信息

  • 总下载量: 518
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固