Z
Z
zvonok782021-08-06 05:55:53
Laravel
zvonok78, 2021-08-06 05:55:53

Why doesn't Orchid custom filtering select multiple options?

Laravel 8.53
Admin Panel: Orchid
php: 8.0

When searching in a custom filter, when selecting multiple fields, only the last 1 field is always substituted.
For example, the filter consists of 4 fields: City, Category, Brand, Model.
If you select City, then there will be records by city, but if you then select Category or another field, then the search will be only for the last selected field, and the first condition is deleted. Made according to the video guide from Ilya Chubarov " Laravel

Orchid Admin Panel. Lesson #15. Advanced Filtering "

public $parameters = ['town'];

    public function name(): string
    {
        return 'Город';
    }

    public function run(Builder $builder): Builder
    {
        return $builder->where('id_town', $this->request->get('town'));
    }

    public function display(): array
    {
        return [
            Select::make('town')
                ->options(TownModel::orderBy('title','asc')->get()->pluck('title','id'))
                ->empty()
                ->value($this->request->get('town'))
                ->title('Город')
        ];
    }

for other filters in the same vein.

Created a file combining these filters php artisan orchid:selection FilterVehicleProductsSelection
public function filters(): array
  {
    return [
      TownFilter::class,
      CategoryFilter::class,
      VehicleMarksFilter::class,
      VehicleModelsFilter::class
    ];
  }


I registered everything in the VehicleProductsScreen.php screen
public function query(): array
  {
    return [
      'vehicle_products' => VehicleProductModel::filtersApplySelection(FilterVehicleProductsSelection::class)->filters()->defaultSort('up_at','asc')->paginate(20)
    ];

  public function layout(): array
  {
    return [
      FilterVehicleProductsSelection::class,
      VehicleProductsTable::class,      
    ];
  }

  }


The custom filter is shown with the required parameters, but it filters only by the last selected parameter, it does not want to use several parameters. Day killed for analysis, but did not understand anything. Can anyone shed some light on why this is?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inFureal, 2021-08-19
@inFureal

Maybe because there is no $allowedFilters/ property in the model $allowedSorts?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question