F
Filamentβ€’16mo ago
buzkall

activeLocale error in ListResource using Filament Spatie Translatable

I'm trying to set a translatable resource in a new v3 Filament install. I've added the Actions\LocaleSwitcher in the getHeaderActions of the ListRecords class, but it does nothing and the browser console throws: "Livewire: [wire:model="activeLocale"] property does not exist on component" On the edit page works perfectly
Solution:
use ManageRecords\Concerns\Translatable;
Jump to solution
23 Replies
Tin
Tinβ€’16mo ago
Did you add the Trait?
Solution
Tin
Tinβ€’16mo ago
use ManageRecords\Concerns\Translatable;
buzkall
buzkallOPβ€’16mo ago
maybe I'm stupid 😱
Tin
Tinβ€’16mo ago
You are not!
buzkall
buzkallOPβ€’16mo ago
I was going crazy and I had just forget about the trait...
Tin
Tinβ€’16mo ago
hahahaha, we all do that sometimes πŸ˜„
buzkall
buzkallOPβ€’16mo ago
Do you know how I can get the active locale, to use it for example in a filter? i'm trying to filter by a json translatable field and want to modify tthe TernaryFilter queries, but I'm not getting the active locale 😦
Tin
Tinβ€’16mo ago
Hey @buzkall , sorry I had to go. Did you fix it. I think you have a parameter in the trait you can use Try $this->activeLocale
buzkall
buzkallOPβ€’16mo ago
yes, but if I'm inside the filter query can't use $this
Tin
Tinβ€’16mo ago
hmm, you can resolve $livewire in the callback you pass to the filter I think
buzkall
buzkallOPβ€’16mo ago
Tables\Filters\TernaryFilter::make('published')
->queries(
true: fn($query) => $query->where('published->' . $this->activeLocale, '1'),
false: fn($query) => $query->where('published->'.$this->activeLocale, '0')
)
Tables\Filters\TernaryFilter::make('published')
->queries(
true: fn($query) => $query->where('published->' . $this->activeLocale, '1'),
false: fn($query) => $query->where('published->'.$this->activeLocale, '0')
)
that doesn't work and apparently I can't resolve $livewire in the true and false parameters
Tin
Tinβ€’16mo ago
Can you check if you can resolve $livewire with your $query aaah Let me dive in the code a bit This is in a resource right?
buzkall
buzkallOPβ€’16mo ago
yes
Tin
Tinβ€’16mo ago
Can you overide the table query in the ListRecords?
buzkall
buzkallOPβ€’16mo ago
I'm trying to add a filter to the list Yes, but I don't see the point in overriding the table query for a filter
Tin
Tinβ€’16mo ago
I understand, yes
Tin
Tinβ€’16mo ago
Can you overide it just so you add the filter
buzkall
buzkallOPβ€’16mo ago
ok, but I'll have the same problem there, isn't it?
Tin
Tinβ€’16mo ago
If you are in ListRecord page it's a livewire page and y ou will have the access to $this->activeRecord If not, open a new ticket, maybe someone else knows, sooory πŸ™‚
buzkall
buzkallOPβ€’16mo ago
OMG, you're a genius yes, I can use $this->activeLocale there and the filter totally works now!
Tin
Tinβ€’16mo ago
haha, thanks, maybe the solution is a bit hacky, but I cant find think of a better way
buzkall
buzkallOPβ€’16mo ago
Me neither, it was driving me crazy!
inluxc
inluxcβ€’12mo ago
Sorry for my ignorance, I got the following:
Forms\Components\TextInput::make('title')
->afterStateUpdated(function ($state, Set $set, Get $get, $livewire) {
// Get Channel Domain
$domain = Channel::all()->find($get('channel_id'))->value('domain');

// Get Active Language
$languagePrefix = $livewire->activeLocale;

// Get Slug State
$slug = Str::slug($state);

// Generate new Slug
$finalSlug = $domain . '/' . $languagePrefix . '/' . $slug;
$set('slug', $finalSlug);

// Check if Slug Exist


}),
Forms\Components\TextInput::make('title')
->afterStateUpdated(function ($state, Set $set, Get $get, $livewire) {
// Get Channel Domain
$domain = Channel::all()->find($get('channel_id'))->value('domain');

// Get Active Language
$languagePrefix = $livewire->activeLocale;

// Get Slug State
$slug = Str::slug($state);

// Generate new Slug
$finalSlug = $domain . '/' . $languagePrefix . '/' . $slug;
$set('slug', $finalSlug);

// Check if Slug Exist


}),
Working example πŸ˜„ I cant use can't use $this GOT IT πŸ˜„
Want results from more Discord servers?
Add your server