PHP code example of harrald / nova-combobox-filter

1. Go to this page and download the library: Download harrald/nova-combobox-filter 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/ */

    

harrald / nova-combobox-filter example snippets




namespace App\Nova\Filters;

use Harrald\NovaComboboxFilter\NovaComboboxFilter;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;

class OpenPaidStateFilter extends NovaComboboxFilter
{
    /**
     * The displayable name of the filter.
     *
     * @var string
     */
    public $name = 'State';

    /**
     * The name of the column to filter on
     */
    protected function columnName(): string
    {
        return 'state';
    }

    /**
     * Get the filter's available options.
     */
    public function options(Request $request): Collection
    {
        return Collection::make([
            'Open' => 'open',
            'Paid' => 'paid',
        ]);
    }
}

public function options(Request $request): Collection
{
    return User::all()->pluck('id', 'name');
}

/**
 * Get the filters available for the resource.
 *
 * @param NovaRequest $request
 * @return array
 */
public function filters(NovaRequest $request): array
{
    return [
        OpenPaidStateFilter::make(),
    ];
}