Spatie Translatable - Checkbox list

Hello everyone. I am using the "Spatie Translatable" package in the project. When I use the "Checkbox list" the texts are not visible. Where am I doing wrong? Thank you
No description
27 Replies
Eno7x
Eno7x5w ago
@toeknee 😳sorry for the tag
toeknee
toeknee5w ago
I appreciate you are sorry, but try to refrain as per the #✅┊rules Provide the code please.
Eno7x
Eno7x5w ago
class MarineVehicleResource extends Resource
{
use Translatable;

protected static ?string $model = MarineVehicle::class;

public static function form(Form $form): Form
{
return $form->schema([
CheckboxList::make('marineVehiclePackage')
->translateLabel()
->options(MarineVehiclePackage::where('isActive', true)->pluck('name', 'id'))
->columns(2)
->gridDirection('row')
->searchable(),
]);
}

}
class MarineVehicleResource extends Resource
{
use Translatable;

protected static ?string $model = MarineVehicle::class;

public static function form(Form $form): Form
{
return $form->schema([
CheckboxList::make('marineVehiclePackage')
->translateLabel()
->options(MarineVehiclePackage::where('isActive', true)->pluck('name', 'id'))
->columns(2)
->gridDirection('row')
->searchable(),
]);
}

}
Actually, when I use the "Spatie Translatable" Plugin, the "CheckboxList" names do not appear I'm sorry about that. I will pay attention to this
Eno7x
Eno7x5w ago
yep
LeandroFerreira
Is the name a json column? name: "{"en":"xxx"}" ? Are you using HasTranslations in the model?
Eno7x
Eno7x5w ago
{"en": "Test package name", "es": "Nombre del conjunto de pruebas"} Yes in json format Yes, the room is attached.
LeandroFerreira
Did you add HasTranslations to the model?
Eno7x
Eno7x5w ago
Yes Would you like me to share the entire package with you?
LeandroFerreira
what is the output if you remove HasTranslations ?
Eno7x
Eno7x5w ago
I save the data I want to show in the "CheckboxList" here. When I want to show it in the 2nd image, its name is not visible. When I remove "HasTranslations" from the model, I get the same result.
No description
No description
Lara Zeus
Lara Zeus4w ago
can you try using the fork: https://github.com/lara-zeus/translatable its working with me make sure your model MarineVehiclePackage has the translatable trait and you defined the translatable attributes
No description
No description
Eno7x
Eno7x4w ago
Thanks so much for your time. This package worked. Now the names appear, but when the language is changed with "Switcher" there is no change.
Lara Zeus
Lara Zeus4w ago
in this case you will need to query the active locale:
->options(fn(Livewire $livewire) => MarineVehiclePackage::where('isActive', true)->whereLocale('name', $livewire->activeLocale)->pluck('name', 'id'))
->options(fn(Livewire $livewire) => MarineVehiclePackage::where('isActive', true)->whereLocale('name', $livewire->activeLocale)->pluck('name', 'id'))
and import
use Livewire\Component as Livewire;
use Livewire\Component as Livewire;
Eno7x
Eno7x4w ago
This still doesn't work when I try to create a new page.
No description
No description
Lara Zeus
Lara Zeus4w ago
its working for me and this is my code:
CheckboxList::make('marineVehiclePackage')
->options(fn(Livewire $livewire) => Book::whereLocale('title', $livewire->activeLocale)->pluck('title', 'id')),
CheckboxList::make('marineVehiclePackage')
->options(fn(Livewire $livewire) => Book::whereLocale('title', $livewire->activeLocale)->pluck('title', 'id')),
you do have the trait Translatable in the create page class?
Lara Zeus
Lara Zeus4w ago
test:
->options(fn(Livewire $livewire) => dd($livewire->activeLocale)),
->options(fn(Livewire $livewire) => dd($livewire->activeLocale)),
Eno7x
Eno7x4w ago
Oh yes. If you want to take a look, it's here
Lara Zeus
Lara Zeus4w ago
what the output of ->options(fn(Livewire $livewire) => dd($livewire->activeLocale)), it should return the active locale, when you switch
Eno7x
Eno7x4w ago
Actually, I do everything you say, but I can't get the result I want. Is there a chance you could share the source if you don't mind ?
Lara Zeus
Lara Zeus4w ago
this is the versions I am using the fork lara-zeus/translatable but I checked its also working with the filament/spatie-laravel-translatable-plugin/translatable
No description
Eno7x
Eno7x4w ago
I tried everything you suggested again. But I still get the same result. I did as you said in the example below. When I show this on the new content creation page, the language selector does not show the result. I'm sharing the example if you want to check it out. Thank you very much for your time 😭
Lara Zeus
Lara Zeus4w ago
if you can share the code on a repo or git gist I will look into it
Eno7x
Eno7x4w ago
https://github.com/engbz/demo Thank you very much
GitHub
GitHub - engbz/demo
Contribute to engbz/demo development by creating an account on GitHub.
Lara Zeus
Lara Zeus4w ago
my code didnt work on your app not sure why, but try this:
->options(function (Livewire $livewire) {
return Book::query()
->whereNotNull("title->{$livewire->activeLocale}")
->get()
->mapWithKeys(function($item) use($livewire){
return [$item->id=>$item->getTranslation('title',$livewire->activeLocale)];
});
})
->options(function (Livewire $livewire) {
return Book::query()
->whereNotNull("title->{$livewire->activeLocale}")
->get()
->mapWithKeys(function($item) use($livewire){
return [$item->id=>$item->getTranslation('title',$livewire->activeLocale)];
});
})
Eno7x
Eno7x4w ago
Oh you are amazing. Finally the problem was fixed. You spent a lot of time on this. Thank you very much indeed 😊
Want results from more Discord servers?
Add your server