l5-repository
l5-repository copied to clipboard
parserFieldsSearch method has a bug, please fixed it.
- These are some codes.
`
class ConfigRepositoryEloquent extends BaseRepository implements ConfigRepository
{
protected $fieldSearchable = [
'name',
];
//…
` 2. I use these query params
`
?search=hello&searchFields=namee:like
`
- The flow errors occurs.
`
{ "message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'configs.namee' in 'where clause' (SQL: select * from `configs` where (`configs`.`namee` like %hello%)…
`
- So, I read the code about parserFieldsSearch method in Prettus\Repository\Criteria\RequestCriteria. I think it has a bug, and I use the follow code to fixed it. I hope you could fixed the bug soon.
`
protected function parserFieldsSearch(array $fields = [], array $searchFields = null)
{
if (!is_null($searchFields) && count($searchFields)) {
$acceptedConditions = config('repository.criteria.acceptedConditions', [
'=',
'like'
]);
$originalFields = $fields;
$fields = [];
//these are my codes begin
foreach ($searchFields as $field) {
$field_parts = explode(':', $field);
if(in_array($field_parts[0], $originalFields)) {
if(count($field_parts) == 2 && in_array($field_parts[1], $acceptedConditions)) {
$fields[$field_parts[0]] = $field_parts[1];
} else {
$fields[$field_parts[0]] = '=';
}
}
}
// these are my codes end
if (count($fields) == 0) {
throw new \Exception(trans('repository::criteria.fields_not_accepted', ['field' => implode(',', $searchFields)]));
}
}
return $fields;
}
`
- I thik the follow message is what we expect.
`
{ "message": "repository::criteria.fields_not_accepted", "exception": "Exception", "file": "D:\\www\\hero-api\\app\\Criteria\\BaseRequestCriteria.php",
`
In the $fieldsSearchable you declare "name" while in the search you search for "namee".
i have same issue, but in filter
that not has a valid column