spatie / laravel-schemaless-attributes

Add schemaless attributes to Eloquent models
https://spatie.be/en/opensource
MIT License
1.01k stars 58 forks source link

getRawSchemalessAttributes() must be of the type array, string returned #45

Closed f-liva closed 3 years ago

f-liva commented 5 years ago

When a schemaless column from db is set to NULL instead of {}, on scout:import it results in that error:

Return value of Spatie\SchemalessAttributes\SchemalessAttributes::getRawSchemalessAttributes() must be of the type array, string returned

freekmurze commented 5 years ago

Feel free to submit a PR with tests that fixes this.

chinleung commented 5 years ago

When a schemaless column from db is set to NULL instead of {}, on scout:import it results in that error:

Return value of Spatie\SchemalessAttributes\SchemalessAttributes::getRawSchemalessAttributes() must be of the type array, string returned

Isn't this expected behaviour though? Your database value is most likely set to NULL as a string. Can you confirm for this? 🤔

I've tried to reproduce the issue with a NULL value and it was working properly. The only way I managed was to set NULL as a string.

terranc commented 5 years ago

I have the same problem at PHP v7.2.14

securit commented 5 years ago

Yes this issue is back because the function is type hinted to an array,

    protected function getRawSchemalessAttributes(): array

but it calls the return function fromJson which returns a mixed type.

securit commented 4 years ago

This problem appears to be an issue still, particularly for those of us using Postgres when you have a null object, ie {}::json.

BinaryKitten commented 4 years ago

move to close: has this been resolved by #60 ? (came here via good first issue)

erikn69 commented 3 years ago

move to close: has this been resolved by #60 ? (came here via good first issue)

X2