adminarchitect / core

AdminArchitect - Active Admin for Laravel
http://adminarchitect.com
MIT License
211 stars 66 forks source link

update method for filters doesnt work. #70

Closed xhevatziberi closed 5 years ago

xhevatziberi commented 5 years ago

public function filters() { return $this->scaffoldFilters()->update('phone', ... throws an error "Element [phone] does not exist." even if it is present. Another issue for the update is that the control doesn't have a setQuery method, even if in the docs there is an example for filtering relationships that way.

endihunter commented 5 years ago

@xhevattalenta sharing a bit more code could help, thanks. P.S. I would like to see the output of $this->scaffoldFilters() and the rest of filters method.

xhevatziberi commented 5 years ago

Here are the columns of the model Capture a snippet from scaffoldFilters function in Traits\Module\HasFilters.php for this model.

The indexes are of type "BigIntType" and it doesnt satisfy none of the conditions of the switch statement in: https://github.com/adminarchitect/core/blob/34569401a24661f3ef74cbbbb158b98ae41975c7/src/Traits/Module/HasFilters.php#L87 maybe here is the issue?

Here is how I use the filters:

    public function filters()
    {
      return $this->scaffoldFilters()
      ->update("client_id", function ($control) {
        $control->getInput()
        ->setQuery(function ($query, $value) {
          return $query
          ->join('clients as c', 'c.id', '=', 'mounts.client_id')
          ->where('c.name', $value);
        });
        return $control;
      });
    }
endihunter commented 5 years ago

@xhevattalenta it seems that client_id is not auto-discovered by AdminArchitect as a filter (because of Int type). You have to register it (push) as a filter instead of updating. update means you have added a filter before or it was added by AdminArchitect

xhevatziberi commented 5 years ago

@xhevattalenta it seems that client_id is not auto-discovered by AdminArchitect as a filter (because of Int type). You have to register it (push) as a filter instead of updating. update means you have added a filter before or it was added by AdminArchitect

Yes that does the trick. The filter can be added and updated by chaining the methods which is great.