Code Monkey home page Code Monkey logo

nova-attach-many's Introduction

Nova Attach Many

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-many

Installation

composer require dillingham/nova-attach-many

Usage

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);

Display on detail:

This package only provides the create / edit views that BelongsToMany does not.

BelongsToMany should be used 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)

Options

Here are a few customization options

  • ->showCounts() Shows "selected/total"
  • ->showPreview() Shows only selected
  • ->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 filter which resources are able to be attached

Being Notified of Changes

You can add a method to the resource to be notified of the changes that have happened:

The method must be a camel cased version of the attribute name, followed by Synced. For example:

public function fields(Request $request)
{
    return [
        AttachMany::make('Permissions'),
    ];
}
public function permissionsSynced(array $changes)
{
    $changes['attached']; // An array of IDs of attached models
    $changes['detached']; // An array of IDs of detached models
    $changes['updated']; // An array of IDs of updated models
}

Authorization

This field also respects policies: ie Role / Permission

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

Author

Hi ๐Ÿ‘‹, Im Brian D. I created this Nova package and others

Hope you find it useful. Feel free to reach out with feedback.

Follow me on twitter: @im_brian_d

nova-attach-many's People

Contributors

dillingham avatar alberto-bottarini avatar ahmedkandel avatar drsdre avatar niladam avatar mbardelmeijer avatar bdelamatre avatar bsormagec avatar gautierdele avatar mziraki avatar mpaap avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.