From a6a40df773c4c3faddd1967cb232fb6c244eedb5 Mon Sep 17 00:00:00 2001 From: tzelleke Date: Wed, 6 May 2020 19:17:18 +0200 Subject: [PATCH] fix: allow integer zero (0) value when filling attribute When options to the field have integer keys including zero, like: ``` [ 0 => 'Administrator', 1 => 'Moderator', 2 => 'Subscriber', 3 => 'Super administrator' ]; ``` then the field silently drops the zero value when the field fills the attribute. Closes Silvanite/novafieldcheckboxes#32 --- src/Checkboxes.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Checkboxes.php b/src/Checkboxes.php index 12187e0..f3af142 100644 --- a/src/Checkboxes.php +++ b/src/Checkboxes.php @@ -83,7 +83,12 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib if (!is_array($choices = $request[$requestAttribute])) { $choices = collect(explode(',', $choices))->map(function ($choice) { return ($this->shouldNotTypeCast()) ? $choice : $this->castValueToType($choice); - })->filter()->all(); + })->filter(function ($value) { + /** + * Filtering out "falsy" values but allowing for int value zero (0) + */ + return $value === 0 ? true : $value; + })->all(); } $model->{$attribute} = $choices;