Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collection parsing when the value is null #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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