A Laravel Nova field for searchable belongs-to-many relationships
metasync-site/nova-belongs-to-many is a Laravel package for a laravel nova field for searchable belongs-to-many relationships.
It currently has 3 GitHub stars and 2.852 downloads on Packagist (latest version 1.0.6).
Install it with composer require metasync-site/nova-belongs-to-many.
Discover more Laravel packages by metasync-site
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel Nova field that provides a searchable interface for belongs-to-many relationships with the ability to create new related resources.

You can install the package via composer:
composer require metasync-site/nova-belongs-to-many
use MetasyncSite\NovaBelongsToMany\BelongsToManySearchable;
BelongsToManySearchable::make('Products')
->relationshipConfig(
resourceClass: ProductResource::class,
relationName: 'products',
),
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'),
];
}
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 tabledisplayCallback: Customize how each option is displayedwithCreateButton: Enable the create button with an optional custom labelIf you discover any security vulnerabilities, please email [email protected]