I have a Employee table which display like this:
+-------------------------------+
| id | name | code |
---------------------------------
| 1 | Employee 1 | A1 |
| 2 | Employee 2 | A2 |
| ... | ... | ... |
+-------------------------------+
And I want to create a filter by code column in this table. My query will be like this:
SELECT name FROM employee WHERE code LIKE .% $filter %.
I searched in backpack document and trying to do like this
$this->crud->addFilter(
[
'type' => 'select2',
'name' => 'code',
'label' => 'Filter',
],
function () {
return Employee::select('code')->distinct()->get()->toArray();
},
function ($value) {
$this->crud->addClause('where', 'code', $value);
}
);
But it got error: htmlspecialchars() expects parameter 1 to be string, array given
. How I can fix this?
Thank you very much!