PHP code example of metasync-site / nova-belongs-to-many

1. Go to this page and download the library: Download metasync-site/nova-belongs-to-many library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

metasync-site / nova-belongs-to-many example snippets


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'),
    ];
}