#Spatie Translatable - Checkbox list

32 messages · Page 1 of 1 (latest)

fleet swan
#

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

fleet swan
#

@primal zephyr 😳sorry for the tag

primal zephyr
#

I appreciate you are sorry, but try to refrain as per the #✅┊rules

Provide the code please.

fleet swan
#
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

fleet swan
primal zephyr
strong mulch
# fleet swan yep

Is the name a json column? name: "{"en":"xxx"}" ?
Are you using HasTranslations in the model?

fleet swan
#

Yes, the room is attached.

strong mulch
fleet swan
#

Would you like me to share the entire package with you?

strong mulch
fleet swan
sleek ginkgo
fleet swan
sleek ginkgo
#

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'))

and import

use Livewire\Component as Livewire;
fleet swan
sleek ginkgo
#

its working for me and this is my code:

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?

#

test:

->options(fn(Livewire $livewire) => dd($livewire->activeLocale)),
fleet swan
#

Oh yes. If you want to take a look, it's here

sleek ginkgo
#

what the output of
->options(fn(Livewire $livewire) => dd($livewire->activeLocale)),

#

it should return the active locale, when you switch

fleet swan
sleek ginkgo
fleet swan
sleek ginkgo
fleet swan
sleek ginkgo
#

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)];
      });
})