metasync-site / nova-belongs-to-many
A Laravel Nova field for searchable belongs-to-many relationships
Installs: 1 032
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 2
Open Issues: 1
pkg:composer/metasync-site/nova-belongs-to-many
Requires
- php: >=8.2
- laravel/nova: ^4.0|^5.0
README
A Laravel Nova field that provides a searchable interface for belongs-to-many relationships with the ability to create new related resources.
Requirements
- PHP >=8.2
- Laravel 11.x | 12.x
- Laravel Nova 4.x | 5.x
Installation
You can install the package via composer:
composer require metasync-site/nova-belongs-to-many
Usage
use MetasyncSite\NovaBelongsToMany\BelongsToManySearchable; BelongsToManySearchable::make('Products') ->relationshipConfig( resourceClass: ProductResource::class, relationName: 'products', ),
Full api
use MetasyncSite\NovaBelongsToMany\BelongsToManySearchable; public function fields(NovaRequest $request) { return [ BelongsToManySearchable::make('Products') ->relationshipConfig( resourceClass: ProductResource::class, relationName: 'products', pivotTable: 'category_product', foreignPivotKey: 'category_id', relatedPivotKey: 'product_id', displayCallback: fn($product) => "{$product->name} (${$product->price})" ) ->withCreateButton(true, 'Add New Product'), ]; }
Features
- 🔍 Searchable interface for belongs-to-many relationships
- ✨ Custom display formatting with callback support
- ➕ Optional "Create New" button with modal
- 🎨 Dark mode support
- 🎯 Type-safe implementation
- 🔄 Automatic pivot table management
Configuration Options
Required Parameters
resourceClass: The Nova resource class for the related modelrelationName: The name of the relationship method on your modelpivotTable: The name of the pivot tableforeignPivotKey: The foreign key of the parent model in the pivot tablerelatedPivotKey: The foreign key of the related model in the pivot table
Optional Parameters
displayCallback: Customize how each option is displayedwithCreateButton: Enable the create button with an optional custom label
Security Vulnerabilities
If you discover any security vulnerabilities, please email metasyncsite@gmail.com
