承接 nakukryskin/orchid-repeater-field 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nakukryskin/orchid-repeater-field

最新稳定版本:13.0.2

Composer 安装命令:

composer require nakukryskin/orchid-repeater-field

包简介

Adding support of repeater field to the Orchid RAD platform.

README 文档

README

Support Ukraine Badge

Orchid Platform Repeater Field

Brief

We've all worked with WordPress at one time or another. Inspired by Advanced Custom Fields.

This package adding repeater fields support to Orchid RAD platform.

Pre-requirements

You must have installed and configured Orchid Platform

Version Support: .*

For ^13.0.1 use ^13.0.0 tag and newer.

Older versions do not have support for most of the current functionality.

For 6.* version use 2.0.5 tag.

For 5 version use 1.0.0 tag.

For 4.7.1 version use 0.0.8 tag.

How to use

  1. Install package with composer: composer require nakukryskin/orchid-repeater-field

    Latest version of laravel automatically discover package to use.

  2. Create RepeaterFields.php in your Orchid Layouts directory. Example:

 <?php
 
 namespace App\Http\Orchid\Layouts\Repeaters;
 
 use Orchid\Screen\Layouts\Rows;
 use Orchid\Screen\Fields\Input;
 use Orchid\Screen\Fields\Select;
 
 class RepeaterFields extends Rows
 {
     function fields(): array
     {
         return [
             Input::make('repeater_name')
                 ->type('text')
                 ->max(255)
                 ->required()
                 ->title('Nested Field'),
             
             Select::make('select.')
                 ->multiple()
                 ->options([
                     'test' => 'Test',
                     'test2' => 'Test2'
                 ])
                 ->required()
         ];
     }
 }
  1. Simply start adding the RepeaterField::make('repeater') in your screen: Example:
public function layout(): array
{
   return [
       Layout::rows([
           RepeaterField::make('repeater')
               ->title('Repeater')
               ->layout(App\Http\Orchid\Layouts\Repeaters\RepeaterFields::class),
       ])
   ];
}
  1. Open your screen and check that the repeater fields here

Advanced usage

Repeater field also support required, max and min parameters. You can add these parameters with call the RepeaterField.

RepeaterField::make('repeater')
    ->title('Repeater')
    ->layout(App\Http\Orchid\Layouts\Repeaters\RepeaterFields::class)
    ->required()
    ->min(10)
    ->max(20)

If ->required() passed to the constructor automatically will set min to 1. If the user tries to delete this field, it will be prevented and show the message.

You can also change the text when deleting a block using the method ->confirmText('Are you sure that you want to delete the block?').

To show required message on save you must add this rule to your screen rules, eg. 'content.*.repeater' => 'required'

You also can rename button label with your own with method buttonLabel(). eg.

RepeaterField::make('repeater')
    ->title('Repeater')
    ->layout(App\Http\Orchid\Layouts\Repeaters\RepeaterFields::class)
    ->buttonLabel('Add new repeater field')

In extreme cases, if you are using some kind of dynamic data loading and you need to pass additional data to your Layout, use the ->ajaxData() method. This method can work both with a callable function and with an array of data. This can be useful when you need to filter the data for each of the fields.

To use ajaxData, first connect trait AjaxDataAccess to your Layout:

<?php

namespace App\Orchid\Layouts;

use Nakukryskin\OrchidRepeaterField\Traits\AjaxDataAccess;
use Orchid\Screen\Layouts\Rows;
use Orchid\Screen\Fields\Input;
use Orchid\Screen\Fields\Select;

class RepeaterFields extends Rows
{
    use AjaxDataAccess;

    public function fields(): array
    {
        return [
            Select::make('select.')
                ->title('Select')
                ->multiple()
                ->options($this->getSelectOptions())
                ->required(),
        ];
    }
    
    protected function getSelectOptions() {
        return $this->getAjaxData()->get('select_options');
    }
}

After that, on the main screen, determine what you want to transmit. In the example, we generate a list based on the current user role:

Repeater::make('repeater')
      ->title('Repeater')
      ->layout(\App\Orchid\Layouts\RepeaterFields::class)
      ->ajaxData(function () {
          $data = [
              'select_options' => [
                  'default' => 'Default option',
              ],
          ];
   
          if (request()->user()->id === 1) {
              $data['select_options']['only_first'] = 'Option only for user with id #1';
          }
   
          return $data;
      }),

Dynamic ajax data with anonymous function

You can combine output options and what and when to output to the user in your repeater fields. Note that your Layout knows nothing about the state of the other fields on the current screen and, if you want to transfer data about the current fields you must first save the record and use the data and query of your main screen.

Repeater::make('repeater')
         ->title('Repeater')
         ->layout(\App\Orchid\Layouts\RepeaterFields::class)
         ->ajaxData([
             'select_options' => [
                 'default' => $this->query()['name'] ?? 'Default Name',
             ],
         ]),

Using other field from query to

nakukryskin/orchid-repeater-field 适用场景与选型建议

nakukryskin/orchid-repeater-field 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102.55k 次下载、GitHub Stars 达 56, 最近一次更新时间为 2019 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「repeater field」 「Orchid Repeater Field」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nakukryskin/orchid-repeater-field 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nakukryskin/orchid-repeater-field 我们能提供哪些服务?
定制开发 / 二次开发

基于 nakukryskin/orchid-repeater-field 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 102.55k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 57
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 56
  • Watchers: 6
  • Forks: 37
  • 开发语言: PHP

其他信息

  • 授权协议: wtfpl
  • 更新时间: 2019-01-24