chg: [Component:CRUD] Allow to filter out rows from the index with afterFind

Filtering can be achieved by returning `false` instead of the row in the `afterFind` function
pull/93/head
Sami Mokaddem 2022-02-23 09:58:55 +01:00
parent bf3e31c59a
commit 20d896ad47
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 12 additions and 4 deletions

View File

@ -80,13 +80,17 @@ class CRUDComponent extends Component
if (isset($options['afterFind'])) {
$function = $options['afterFind'];
if (is_callable($function)) {
$data->each(function($value, $key) use ($function) {
$data = $data->map(function($value, $key) use ($function) {
return $function($value);
})->filter(function ($value) {
return $value !== false;
});
} else {
$t = $this->Table;
$data->each(function($value, $key) use ($t, $function) {
$data = $data->map(function($value, $key) use ($t, $function) {
return $t->$function($value);
})->filter(function ($value) {
return $value !== false;
});
}
}
@ -100,13 +104,17 @@ class CRUDComponent extends Component
if (isset($options['afterFind'])) {
$function = $options['afterFind'];
if (is_callable($function)) {
$data->each(function($value, $key) use ($function) {
$data = $data->map(function($value, $key) use ($function) {
return $function($value);
})->filter(function($value) {
return $value !== false;
});
} else {
$t = $this->Table;
$data->each(function($value, $key) use ($t, $function) {
$data = $data->map(function($value, $key) use ($t, $function) {
return $t->$function($value);
})->filter(function ($value) {
return $value !== false;
});
}
}