cms icon indicating copy to clipboard operation
cms copied to clipboard

Error returning collection from tag

Open rspenc29 opened this issue 9 months ago • 0 comments

Bug description

I get an error when returning a collection containing an associative array from a tag. Declaring the same collection within a template works, and casting to an array from within the tag before returning also works.

How to reproduce

class MyTag extends Tags {
    public function index() {
        return collect(['a', 'b']); // works
        return collect(['a' => 'b']); // ErrorException: Undefined array key 0 in file [...]/vendor/laravel/framework/src/Illuminate/Collections/Collection.php on line 1780
        return collect(['a' => 'b'])->toArray(); // works
        return ['a' => 'b']; // works
    }
}
{{ $var = {my_tag} }}

Logs

// ErrorException: Undefined array key 0 in file [...]/vendor/laravel/framework/src/Illuminate/Collections/Collection.php on line 1780

Environment

➜  statamic git:(master) ✗ ./please support:details

Environment
Application Name: statamic
Laravel Version: 11.7.0
PHP Version: 8.3.3
Composer Version: 2.5.4
Environment: local
Debug Mode: ENABLED
URL:
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: null
Cache: statamic
Database: mysql
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 1
Sites: 3
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.2.0 PRO

Statamic Addons
statamic/eloquent-driver: 4.0.0

Statamic Eloquent Driver
Asset Containers: eloquent
Assets: eloquent
Blueprints: eloquent
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: eloquent
Navigation Trees: eloquent
Navigations: eloquent
Revisions: eloquent
Taxonomies: eloquent
Terms: eloquent

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

rspenc29 avatar May 17 '24 20:05 rspenc29