Skip to content

Commit 4a25e67

Browse files
committed
Fix a bug with laravel-collective
1 parent 3633a04 commit 4a25e67

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/HtmlGenerators/LaravelCollectiveHtml.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protected function getFieldMinValueWithName($minValue)
2020
{
2121
return is_null($minValue) ? '' : sprintf(" 'min' => '%s',", $minValue);
2222
}
23+
2324
/**
2425
* Gets the maxValue attribute.
2526
*
@@ -31,6 +32,7 @@ protected function getFieldMaxValueWithName($maxValue)
3132
{
3233
return is_null($maxValue) ? '' : sprintf(" 'max' => '%s',", $maxValue);
3334
}
35+
3436
/**
3537
* Get the minLength attribute.
3638
*
@@ -42,6 +44,7 @@ protected function getFieldMinLengthName($minLength)
4244
{
4345
return empty($minLength) ? '' : sprintf(" 'minlength' => '%s',", $minLength);
4446
}
47+
4548
/**
4649
* Gets the maxLength attribute.
4750
*
@@ -53,6 +56,7 @@ protected function getFieldMaxLengthName($maxLength)
5356
{
5457
return empty($maxLength) ? '' : sprintf(" 'maxlength' => '%s',", $maxLength);
5558
}
59+
5660
/**
5761
* Gets the required attribute.
5862
*
@@ -64,6 +68,7 @@ protected function getFieldRequired($required)
6468
{
6569
return $required ? sprintf(" 'required' => %s,", ($required ? 'true' : 'false')) : '';
6670
}
71+
6772
/**
6873
* Get the placeholder attribute.
6974
*
@@ -75,6 +80,7 @@ protected function getFieldPlaceHolder(Label $placeholder = null)
7580
{
7681
return is_null($placeholder) ? '' : sprintf(" 'placeholder' => %s,", $this->getTitle($placeholder));
7782
}
83+
7884
/**
7985
* Get the placeholder attribute for a menu.
8086
*
@@ -87,6 +93,7 @@ protected function getFieldPlaceHolderForMenu(Label $placeholder = null, $name =
8793
{
8894
return $this->getFieldPlaceHolder($placeholder);
8995
}
96+
9097
/**
9198
* Get the multiple attribute.
9299
*
@@ -98,8 +105,9 @@ protected function getFieldMultiple($isMulti)
98105
{
99106
return $isMulti ? "'multiple' => 'multiple'," : '';
100107
}
108+
101109
/**
102-
* It gets converts an array to a stringbase array for the views.
110+
* It gets converts an array to a string based array for the views.
103111
*
104112
* @param CrestApps\CodeGenerator\Models\Field $field
105113
*
@@ -113,6 +121,7 @@ protected function getFieldItems(Field $field)
113121
$labels = $field->getOptionsByLang();
114122
return sprintf('[%s]', implode(',' . PHP_EOL, $this->getKeyValueStringsFromLabels($labels)));
115123
}
124+
116125
/**
117126
* Gets a plain title from a giving label.
118127
*
@@ -125,6 +134,7 @@ protected function getPlainTitle(Label $label, $raw = false)
125134
{
126135
return sprintf(!$raw ? "'%s'" : "%s", $label->text);
127136
}
137+
128138
/**
129139
* Gets the fields value
130140
*
@@ -142,6 +152,7 @@ protected function getFieldValue($value, $name)
142152
}
143153
return 'null';
144154
}
155+
145156
/**
146157
* Gets checked item attribute.
147158
*
@@ -159,6 +170,7 @@ protected function getCheckedItem($value, $name, $defaultValue)
159170
$value
160171
);
161172
}
173+
162174
/**
163175
* Gets selected value attribute.
164176
*
@@ -186,6 +198,7 @@ protected function getMultipleCheckedItem($value, $name, $defaultValue)
186198
{
187199
return sprintf(" (%s ? true : null) ", $this->getMultipleRawOptionValue($name, $value, $defaultValue));
188200
}
201+
189202
/**
190203
* Gets a raw value for a giving field's name.
191204
*
@@ -201,6 +214,7 @@ protected function getRawOptionValue($name, $value)
201214
$accessor = $this->getDefaultValueAccessor($modelVariable, $name, $valueString);
202215
return sprintf("old('%s', %s)", $name, $accessor);
203216
}
217+
204218
/**
205219
* Gets a raw value for a giving field's name.
206220
*
@@ -223,8 +237,10 @@ protected function getMultipleRawOptionValue($name, $value, $defaultValue)
223237
$defaultValueString = sprintf('[%s]', $joinedValues);
224238
}
225239
$accessor = $this->getDefaultValueAccessor($modelVariable, $name, $defaultValueString);
226-
return sprintf("in_array(%s, old('%s', %s))", $valueString, $name, $accessor);
240+
241+
return sprintf("in_array(%s, old('%s', %s) ?: [])", $valueString, $name, $accessor);
227242
}
243+
228244
/**
229245
* Gets the best value accessor for the view
230246
*
@@ -245,6 +261,7 @@ protected function getDefaultValueAccessor($modelVariable, $property, $value)
245261
}
246262
return sprintf("isset(\$%s->%s) ? \$%s->%s : %s", $modelVariable, $property, $modelVariable, $property, $value);
247263
}
264+
248265
/**
249266
* Gets selected value attribute.
250267
*
@@ -258,6 +275,7 @@ protected function getMultipleSelectedValue($name, $valueAccessor, $defaultValue
258275
{
259276
return sprintf(" (%s ? true : null) ", $name);
260277
}
278+
261279
/**
262280
* Gets the html steps attribute.
263281
*
@@ -269,6 +287,7 @@ protected function getStepsValue($value)
269287
{
270288
return ($value) > 0 ? "'step' => \"any\"," : '';
271289
}
290+
272291
/**
273292
* Gets an instance of ViewLabelsGenerator
274293
*

src/HtmlGenerators/StandardHtml.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,7 @@ protected function getMultipleRawOptionValue($name, $value, $defaultValue)
289289

290290
$accessor = $this->getDefaultValueAccessor($modelVariable, $name, $defaultValueString);
291291

292-
if (Helpers::isNewerThanOrEqualTo('5.5')) {
293-
return sprintf("in_array(%s, old('%s', %s) ?? [])", $valueString, $name, $accessor);
294-
}
295-
296-
return sprintf("in_array(%s, (array) old('%s', %s))", $valueString, $name, $accessor);
292+
return sprintf("in_array(%s, old('%s', %s) ?: [])", $valueString, $name, $accessor);
297293
}
298294

299295
/**

0 commit comments

Comments
 (0)