Fix AdminDirectoryController 500 on media_types validation

The media_types closure validator called $value->toArray(), but the
value is a plain PHP array (built via explode()), causing a fatal
'Call to a member function toArray() on array' and a 500 when opening
the Directory admin view.

Normalize to an array before in_array() checks, handling both array
and Collection inputs.

Fixes #7311
pull/7321/head
Your Name 1 week ago
parent f1effd1621
commit 6c90810f4a

@ -101,7 +101,8 @@ trait AdminDirectoryController
'media_types' => [
'required',
function ($attribute, $value, $fail) {
if (! in_array('image/jpeg', $value->toArray()) || ! in_array('image/png', $value->toArray())) {
$types = is_array($value) ? $value : collect($value)->toArray();
if (! in_array('image/jpeg', $types) || ! in_array('image/png', $types)) {
$fail('You must enable image/jpeg and image/png support.');
}
},
@ -269,7 +270,8 @@ trait AdminDirectoryController
'media_types' => [
'required',
function ($attribute, $value, $fail) {
if (! in_array('image/jpeg', $value->toArray()) || ! in_array('image/png', $value->toArray())) {
$types = is_array($value) ? $value : collect($value)->toArray();
if (! in_array('image/jpeg', $types) || ! in_array('image/png', $types)) {
$fail('You must enable image/jpeg and image/png support.');
}
},

Loading…
Cancel
Save