Skip to content

Js::from() returns null when passed an empty collection #53205

@PHLAK

Description

@PHLAK

Laravel Version

11.28.1

PHP Version

8.3.12

Database Driver & Version

N/A

Description

In Laravel <= 11.27.2 passing an empty array or collection to Js::from() would return an empty array (i.e. []).

> (string) Js::from([])
= "[]"

> (string) Js::from(new Collection)
= "[]"

With the application of #53096 in Laravel 11.28.0 Js::from() started returning null when passed an empty array or collection.

> (string) Js::from([])
= "null"

> (string) Js::from(new Collection)
= "null"

This was fixed for arrays in #53181 and released with Laravel 11.28.1, however, this is still an issue for collections.

> (string) Js::from([])
= "[]"

> (string) Js::from(new Collection)
= "null"

Steps To Reproduce

Pass an empty collection into Js::from() when running Laravel 11.28.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions