Skip to content

Commit 61bb1a2

Browse files
authored
Fix deprecation message if str_replace receive a null value in FormHelper (#689)
1 parent b67d2d0 commit 61bb1a2

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/Kris/LaravelFormBuilder/Form.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ public function getName()
644644
**/
645645
public function getNameKey()
646646
{
647+
if ($this->name === null) {
648+
return '';
649+
}
650+
647651
return $this->formHelper->transformToDotSyntax($this->name);
648652
}
649653

src/Kris/LaravelFormBuilder/FormHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public function appendMessagesWithPrefix(MessageBag $messageBag, $prefix, array
456456
*/
457457
public function transformToDotSyntax($string)
458458
{
459-
return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $string);
459+
return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $string ?? '');
460460
}
461461

462462
/**

tests/FormBuilderTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function buildForm()
6565

6666
public function alterFieldValues(array &$values)
6767
{
68-
$values['body'] = strtoupper($values['body']);
68+
$values['body'] = strtoupper($values['body'] ?? '');
6969
}
7070

7171
public function alterValid(Form $mainForm, &$isValid)

0 commit comments

Comments
 (0)