laravel-admin icon indicating copy to clipboard operation
laravel-admin copied to clipboard

May be the inputFilter have a Bug, when the filter value eq string "0"

Open xxl4 opened this issue 7 months ago • 0 comments

  • Laravel Version: #.#.#
  • PHP Version: 7.4
  • Laravel-admin: #.#.#

master

Description:

When my code have status include 0, the input filter don't work fine.

`

/**
 * Add a binding to the query.
 *
 * @param string     $value
 * @param Model|null $model
 */
public function addBinding($value, Model $model)
{
    if (empty($value)) {  // when value is string "0" will not work fine
        return;
    }

    if ($this->type == 'like') {
        $model->where($this->getColumnName(), 'like', "%{$value}%");

        return;
    }

    if (in_array($this->type, ['date', 'time'])) {
        $method = 'where'.ucfirst($this->type);
        $model->{$method}($this->getColumnName(), $value);

        return;
    }

    $model->where($this->getColumnName(), $value);
}

`

so and now , fix it to

`

/** * Add a binding to the query. * * @param string $value * @param Model|null $model */ public function addBinding($value, Model $model) {

    if (empty($value)) {
        //return;
    }
    
    if($value==NULL) {
        return ;
    }


    if ($this->type == 'like') {
        $model->where($this->getColumnName(), 'like', "%{$value}%");

        return;
    }

    if (in_array($this->type, ['date', 'time'])) {
        $method = 'where'.ucfirst($this->type);
        $model->{$method}($this->getColumnName(), $value);

        return;
    }

    $model->where($this->getColumnName(), $value);
}

`

pls check it, thank you!

Steps To Reproduce:

xxl4 avatar Nov 17 '23 12:11 xxl4