andersao / andersao/l5-repository

Failed to search 0 value

Abierto
#582 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
PHP
Estrellas
4.2k
Forks
880
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hi,
I was using this repository to find a boolean value which is stored as integer in MySQL thorugh RequestCriteria. But it failed.
After digging deeper to the source code, I found that the code checks if search or not by its content:
```php
...
if ($search && is_array($fieldsSearchable) && count($fieldsSearchable)) {
}
...
```
[code](
https://github.com/andersao/l5-repository/blob/f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4/src/Prettus/Repository/Criteria/RequestCriteria.php#L49)

So if you are searching a value which is [falsy](http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting), then it won't search.

The solution is simple, use `is_null` to check the `$search`:
```php
if (!is_null($search) && is_array($fieldsSearchable) && count($fieldsSearchable)) {
}
```

Thanks.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.