定制 blendbyte/nova-attach-many 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

blendbyte/nova-attach-many

Composer 安装命令:

composer require blendbyte/nova-attach-many

包简介

BelongsToMany attach UI for Laravel Nova — searchable, validatable, with sync notifications & policy support. Fork of dillingham/nova-attach-many, maintained for Nova 5.

README 文档

README

Latest Version on Packagist Software License

BelongsToMany create & edit form UI for Laravel Nova. Enables attaching relationships easily and includes validation.

Forked from dillingham/nova-attach-many.

attach-many

Installation

composer require blendbyte/nova-attach-many

Quick Start

use NovaAttachMany\AttachMany;

public function fields(Request $request)
{
    return [
        AttachMany::make('Permissions'),
    ];
}

You can explicitly define the relationship & Nova resource:

AttachMany::make('Field Name', 'relationshipName', RelatedResource::class);

Pivot Values

You can pass additional parameters for any pivot value. See the Laravel docs on syncing associations for details.

AttachMany::make('Field Name', 'relationshipName', RelatedResource::class, ['pivot_name' => value]);

Display on Detail

This package only provides the create/edit views that BelongsToMany does not. Use BelongsToMany for displaying the table on detail views:

public function fields(Request $request)
{
    return [
        AttachMany::make('Permissions'),
        BelongsToMany::make('Permissions'),
    ];
}

Validation

You can set min, max, size or custom rule objects:

->rules('min:5', 'max:10', 'size:10', new CustomRule)

validation example

Options

Method Description
->showCounts() Shows "selected / total"
->showPreview() Shows only selected items
->hideToolbar() Removes search & select all
->height('500px') Set custom height
->fullWidth() Set to full width
->showRefresh() Request the resources again
->showSubtitle() Show the resource's subtitle
->help('<b>Tip:</b> help text') Set the help text

all options demo

Relatable

The attachable resources will be filtered by relatableQuery(), so you can control which resources are available for attachment.

Being Notified of Changes

Add a method to the resource to be notified of sync changes. The method must be a camel-cased version of the attribute name, followed by Synced:

public function fields(Request $request)
{
    return [
        AttachMany::make('Permissions'),
    ];
}

public function permissionsSynced(array $changes)
{
    $changes['attached']; // IDs of attached models
    $changes['detached']; // IDs of detached models
    $changes['updated'];  // IDs of updated models
}

Authorization

This field respects policies. For example, with a Role / Permission setup:

  • RolePolicy: attachAnyPermission($user, $role)
  • RolePolicy: attachPermission($user, $role, $permission)
  • PermissionPolicy: viewAny($user)

Maintained by Blendbyte


Blendbyte

Blendbyte builds cloud infrastructure, web apps, and developer tools.
We've been shipping software to production for 20+ years.

This package runs in our own stack, which is why we keep it maintained.
Issues and PRs get read. Good ones get merged.


blendbyte.com · hello@blendbyte.com

统计信息

  • 总下载量: 382.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 1
  • Forks: 112
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固