You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to implement the HasTranslations Trait in a Model with preexistent data in database.
In order to convert data I've executed the following code in the migration, before converting text field into json:
It fails when executing setTranslation on a field which value is "10" because in line 81 of HasTranslations.php json_decode($this->getAttributes()[$key] ?? '' ?: '{}', true)
is returning int(10) and array_filter fails with:
PHP Warning: array_filter() expects parameter 1 to be array, int given in C:/Users/psalvador/Dropbox/PROJECTES/enlavertical.com/laravel8.enlavertical.com/vendor/spatie/laravel-translatable/src/HasTranslations.php on line 81
TypeError: Return value of App/Models/Via::getTranslations() must be of the type array, null returned
I've found this solution that works for my migration:
This discussion was converted from issue #249 on December 21, 2020 11:42.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to implement the HasTranslations Trait in a Model with preexistent data in database.
In order to convert data I've executed the following code in the migration, before converting text field into json:
It fails when executing setTranslation on a field which value is "10" because in line 81 of HasTranslations.php
json_decode($this->getAttributes()[$key] ?? '' ?: '{}', true)
is returning int(10) and array_filter fails with:
PHP Warning: array_filter() expects parameter 1 to be array, int given in C:/Users/psalvador/Dropbox/PROJECTES/enlavertical.com/laravel8.enlavertical.com/vendor/spatie/laravel-translatable/src/HasTranslations.php on line 81
TypeError: Return value of App/Models/Via::getTranslations() must be of the type array, null returned
I've found this solution that works for my migration:
Beta Was this translation helpful? Give feedback.
All reactions