Polyscope - The agent-first dev environment for Laravel

Nova Attach Many

dillingham/nova-attach-many image

Nova Attach Many stats

Downloads
1.5M
Stars
274
Open Issues
22
Forks
100

View on GitHub →

Attach Many Nova field

Nova Attach Many

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

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

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Dillingham Nova Attach Many Related Articles

Hiding Laravel Artisan Console Commands from the list of available commands image

Hiding Laravel Artisan Console Commands from the list of available commands

Read article
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift