PHP code example of metasync-site / nova-has-many-searchable

1. Go to this page and download the library: Download metasync-site/nova-has-many-searchable 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-has-many-searchable example snippets


use MetasyncSite\NovaHasManySearchable\HasManySearchable;

public function fields(NovaRequest $request)
{
    return [
        HasManySearchable::make('Coupons')
            ->relationshipConfig(
                resourceClass: CouponsResource::class,
                foreignKey: 'GoodsDataId',
                displayCallback: function ($coupon) {
                    return "{$coupon?->Name} (Type: {$coupon->Type})";
                }
            )
            ->withCreateButton(true, 'Create New Coupon'),
    ];
}

HasManySearchable::make('Coupons')
    ->relationshipConfig(
        resourceClass: CouponsResource::class,
        foreignKey: 'GoodsDataId',
        displayCallback: fn($model) => "{$model->name} ({$model->code})"
    )

HasManySearchable::make('Coupons')
    ->withCreateButton(true, 'Add New Coupon')