Skip to content

Fix collection parsing when the value is null#1

Open
tgeorgel wants to merge 1 commit intoricventu:masterfrom
tgeorgel:master
Open

Fix collection parsing when the value is null#1
tgeorgel wants to merge 1 commit intoricventu:masterfrom
tgeorgel:master

Conversation

@tgeorgel
Copy link

@tgeorgel tgeorgel commented Jul 4, 2023

Hey, thanks for your work on this :)

This PR fixes the issue when a collection field is created with null as default value :

Setting::name('lorem')->collection();

When using a Json Resource in a controller, which would convert the settings attribute to it's json representation, the following error is thrown :

json_decode(null, true, 512, JSON_THROW_ON_ERROR)

DEPRECATED  json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in /var/www/marketing-smseval()'d code.

JsonException  Syntax error.

To address this issue, adding a default value to "{}" would parse the value as an empty collection :

json_decode($value ?? '{}', true, 512, JSON_THROW_ON_ERROR)
= []

It would be a nice idea to submit the package to packagist also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant