From bf0aa32199c4f3d8003c6da172e98eea76809706 Mon Sep 17 00:00:00 2001 From: Allan Jensen Date: Sun, 7 Apr 2024 12:44:01 +0200 Subject: [PATCH] fix: ensure we don't try to load read-only attributes --- src/generators/crud2/default/search.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/generators/crud2/default/search.php b/src/generators/crud2/default/search.php index cd0c8b8..2db4862 100644 --- a/src/generators/crud2/default/search.php +++ b/src/generators/crud2/default/search.php @@ -148,6 +148,13 @@ public function search($params) { // 'sort' => ['defaultOrder' => ['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()) {