Added filter by region

This commit is contained in:
2023-12-01 00:22:49 +05:00
parent 5ebcc60bd5
commit cee905ec77
7 changed files with 65 additions and 5 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Nova\Filters;
use App\Repos\System\Settings\Location\RegionRepo;
use Laravel\Nova\Filters\Filter;
use Laravel\Nova\Http\Requests\NovaRequest;
class RegionFilter extends Filter
{
/**
* The filter's component.
*
* @var string
*/
public $component = 'select-filter';
/**
* Get the displayable name of the filter.
*
* @return string
*/
public function name(): string
{
return __('Region');
}
/**
* Apply the filter to the given query.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function apply(NovaRequest $request, $query, $value)
{
return $value ? $query->where('region', $value) : $query;
}
/**
* Get the filter's available options.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function options(NovaRequest $request): array
{
return array_flip(RegionRepo::values());
}
}