JSON columns issue
I'm creating a new application which has multiple languages, Arabic and english, so i made the title column type as JSON to accept multiple types eg. (title:{"ar":"lorem","en":"impsum"}) then i managed to install spatie translateable package and plugin. However in Select Input or SelectFilter the data appears as showing in the pictures, the Select input in the create/edit page can be sroted by adding options() with a query that gets the required data however that doesn't seem to work in SelectFilter for some reason.
Solution:Jump to solution
Thanks to @awcodes the issue got sorted after raising the case as an issue in filament repo. here is the link to solution:
https://github.com/filamentphp/filament/issues/9033#event-10646961042...
GitHub
Translatable Columns Appears as JSON on the Dashboard · Issue #903...
Package filament/filament Package Version v3.0.63 Laravel Version v10.25.2 Livewire Version v3.0.5 PHP Version 8.1.0 Problem description Whenever there is a column that is translatable, it appears ...
25 Replies
I've seen similar with relationships, I'm not sure if it's a bug in Spatie's package or not, but it looks like it's not parsing the locale when querying a relationship.
hey there @awcodes, Thank you for responding, I'm glad that I managed to reach you, the issue is that it can be fixed if you managed to add ->options() with a query that gets the related data but it only works with Select, however in SelectFilter it doesn't seem to work the image provided is in the Select case you can see that adding options() fixed it
but in SelectFilter that doesn't seem to work
yea, i'm seeing it happen in general. not even with a select. that's why i'm wondering if it's an issue in the Spatie package.
like, in tinkerwell, if i just grab a model from the DB and look at it's relationships, the related models have both languages instead of the current locale, while the parent record is translated correctly
I think that's correct, due to the fact that the CategoryResource shows the data as it should be and even has the availability to switch between languages when the translatable plugin is used.
Is there any sort of workaround that i can do to make it work? I tried all the available options and it doesn't seem to work 😓
I think there's actually an open issue on the repo for this. I'm not sure of a work around though, other than possibly modifying the query to explicitly return the current locale's value.
by modifying query you mean modify it in ->options() or ->relationship() ? because i tried using options() and didn't work while relationships could figure out how as it kept giving out errors
As an update, this what've reached to:
but yet still giving the same outcome for some reason despite the fact that when i run dd() it shows the correct outcome
Odd
What if you tried:
sorry for responding late, I just tried it and that was the outcome
I adjusted your code to be the below and the error was gone, but still giving the same outcome:
Maybe?
definitely something odd going on here.
this error came up
but there is an interesting thing happening here
I tried running
dump
on the code like this :
and that was the outcome in the photo. i removed the json_decode
as it was the source of the error then the [locale]
gave an error as it was considered as an empty key. so i thought of applying dump()
on $category->title
to see what it gives out and surprisingly it gives the desired outcome!! so why it showing json despite being printed as string ?and btw, these values are the "en" key values of each row so it's a perfect response, but when i remove the
dump
it prints the data as json again!As additional info these accordingly are
Category.php
Service.php
models the ServiceResource
is what I'm trying to implement the category filter onI tried changing
json
to array
and it was the same outcomeHmm. Definitely a head scratcher. I’ll let you know if I think of something.
I really want to thank you for the time that you've given and being patient with me 🙏
Thank you for being patient with me. Lol.
@awcodes Hey there, We discussed this issue about a month ago unfortunately i tried all means possible to tackle it but it still there, I even upgraded to Filament v3.0.63 but with no luck.
i even tried to install behzansalleh/languageswitcher in order to switch between languages in the hopes of fixing it but it did nothing.
In the picture attached you're going to find that the select is reversed and that's due to the whole admin panel is switched to another language (Arabic) but still the same
Yea, I'm seeing this in other places too. I'm still not sure if there's a bug in Spatie's package or Filament where translations are getting read out with relationships.
If this helps, it mostly occurs with options that are generated by a relationship, like for example, the picture is for a table of services and being filtered by categories, they are connected via many-to-many relationship and relationship("categories","title") is added
I tried removing the relationship and adding the options via -
options() only but it returned an error saying categories doesn't exist, I changed it to category_id , but still no luck
If that helps too, I've been working on a project with the same requirements for language switcher and it's working but that's filament 2 not 3
Hey there, sorry to be a bother, Is there any updates about this issue? because i tried it on a checkbox list and gave the same outcome and there seems to be no workaround for it
Solution
Thanks to @awcodes the issue got sorted after raising the case as an issue in filament repo. here is the link to solution:
https://github.com/filamentphp/filament/issues/9033#event-10646961042
GitHub
Translatable Columns Appears as JSON on the Dashboard · Issue #903...
Package filament/filament Package Version v3.0.63 Laravel Version v10.25.2 Livewire Version v3.0.5 PHP Version 8.1.0 Problem description Whenever there is a column that is translatable, it appears ...