Describe the bug
An error occurs when using the withMapValuesToSelectionOptions method to map collection values. The package attempts to access a collection method as a property, resulting in a HigherOrderCollectionProxy instead of retrieving the first item.
Steps to Reproduce
Using the following configuration on a field:
->withMapValuesToSelectionOptions(function ($models) {
return $models->map(function ($model) {
return [
'id' => $model->id,
'label' => $model->name,
];
});
})
Expected Behavior
The options should be mapped successfully without throwing an error.
Actual Behavior / Stack Trace
The following error is thrown:
{
"class": "Error",
"message": "Cannot use object of type Illuminate\\Support\\HigherOrderCollectionProxy as array",
"code": 0,
"file": "/var/www/inb/vendor/ziffmedia/nova-select-plus/src/SelectPlus.php:372",
"trace": [
"/var/www/inb/vendor/ziffmedia/nova-select-plus/src/SelectPlus.php:205"
]
}
Proposed Solution
The issue occurs in SelectPlus.php on line 372 because $options->first is being called as a property instead of a method, which returns a HigherOrderCollectionProxy.
Current code:
$first = $options->first; // Returns HigherOrderCollectionProxy
if (!isset($first['label'])) { // Throws Error
Suggested fix:
Change it to call first() as a method:
$first = $options->first();
Describe the bug
An error occurs when using the
withMapValuesToSelectionOptionsmethod to map collection values. The package attempts to access a collection method as a property, resulting in aHigherOrderCollectionProxyinstead of retrieving the first item.Steps to Reproduce
Using the following configuration on a field:
Expected Behavior
The options should be mapped successfully without throwing an error.
Actual Behavior / Stack Trace
The following error is thrown:
{ "class": "Error", "message": "Cannot use object of type Illuminate\\Support\\HigherOrderCollectionProxy as array", "code": 0, "file": "/var/www/inb/vendor/ziffmedia/nova-select-plus/src/SelectPlus.php:372", "trace": [ "/var/www/inb/vendor/ziffmedia/nova-select-plus/src/SelectPlus.php:205" ] }Proposed Solution
The issue occurs in
SelectPlus.phpon line 372 because$options->firstis being called as a property instead of a method, which returns aHigherOrderCollectionProxy.Current code:
Suggested fix:
Change it to call
first()as a method: