Skip to content

Commit

Permalink
fix: ensure we don't try to load read-only attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
winternet-studio committed Apr 7, 2024
1 parent 6fc445a commit bf0aa32
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/generators/crud2/default/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ public function search($params) {
// 'sort' => ['defaultOrder' => ['<?= $generator->getSearchAttributes()[0] ?>' => SORT_ASC]],
]);

// Remove non-searchable attributes - eg. custom getters since they are read-only (unless we make a setter and add it to searchable())
if (!empty($params[$shortModelName])) {
$params[$shortModelName] = array_filter($params[$shortModelName], function($attribute) use (&$searchable) {
return in_array($attribute, $searchable);
}, ARRAY_FILTER_USE_KEY);
}

$this->load($params);

if (!$this->validate()) {
Expand Down

0 comments on commit bf0aa32

Please sign in to comment.