manojo123/nova-attach-pivot

Attach Pivot Nova field

1.0.18 2020-12-12 22:39 UTC

This package is auto-updated.

Last update: 2022-09-29 03:14:53 UTC


README

  • You can use attachPivot field with pivot Fields.
  • You can search elements by custom fields instead only name

Nova Attach Pivot

Forked from Dillingham's REPO. Changed the name to avoid dependencies conflicts. I will be so grateful if someone can use this branch and finish the TODO list.

Latest Version on Github Total Downloads Twitter Follow

Belongs To Many create & edit form UI for Nova. Enables attaching relationships easily and includes validation.

attach-pivot

Installation

composer require manojo123/nova-attach-pivot

Usage

use NovaAttachPivot\AttachPivot;
public function fields(Request $request)
{
    return [
        AttachPivot::make('Permissions'),
    ];
}

Validation

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

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

52160802-9ee9ac80-2689-11e9-9657-80e3c0d83b27.png

Options

Here are a few customization options

  • ->showCounts() Shows "selected/total"
  • ->pivotFields(['qty']) Adds pivot fields to be attached inline
  • ->searchableFields(['bar_code']) Search box can find by name plus all fields defined in this method
  • ->showPreview() Shows only selected
  • ->hideToolbar() Removes search & select all
  • ->height('500px') Set custom height
  • ->fullWidth() Set to full width
  • ->help('<b>Tip:</b> help text') Set the help text

All Options Demo

53781117-6978ee80-3ed5-11e9-8da4-d2f2408f1ffb.png

Relatable

The attachable resources will be filtered by relatableQuery() So you can filter which resources are able to be attached

Authorization

This field also respects policies: ie Role / Permission

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

TODO

[] Add pagination for large amount of resources [] Pass Nova Fields instead array of strings in pivotFields with full field framework customization. (Rules, Types, etc) [] Refactorate code and perform some unit tests.