PHP code example of oleksiypetlyuk / nova-range-filter

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

    

oleksiypetlyuk / nova-range-filter example snippets

 php



namespace App\Nova\Filters\Profile;

use App\Models\Profile\Profile;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Oleksiypetlyuk\NovaRangeFilter\NovaRangeFilter;

class HourlyPriceFilter extends NovaRangeFilter
{
    public $name = 'Price range';

    public function __construct()
    {
        $this->min = floor(Profile::min('hourly_price'));

        $this->max = ceil(Profile::max('hourly_price'));

        parent::__construct();
    }

    /**
     * Apply the filter to the given query.
     *
     * @param  Request $request
     * @param  Builder $query
     * @param  mixed $value
     * @return Builder
     */
    public function apply(Request $request, $query, $value)
    {
        return $query->whereBetween('hourly_price', $value)
            ->orWhereNull('hourly_price');
    }
}