F
Filamentβ€’8mo ago
RobinDev

Repeater relationship translation not working

When you use repeater relationship translations the relationships does not save per locale, and when switching locale it crashes sometimes. See: https://share.cleanshot.com/b7gdrBZk
CleanShot Cloud
CleanShot 2023-11-08 at 12.55.14
Video uploaded to CleanShot Cloud
84 Replies
RobinDev
RobinDevβ€’8mo ago
Is this fixed? @Dan Harrin Can i maybe help with this
Dan Harrin
Dan Harrinβ€’8mo ago
please stop @ing me, there is no system of priority between bug reports for non-sponsors, especially for bug reports that havent been properly filed on github you can always submit a PR if you want to help
RobinDev
RobinDevβ€’8mo ago
It has been filed on github, 21 september by someone else, is this filed correctly? https://github.com/filamentphp/filament/issues/8656
GitHub
Issue with repeater and builder when saving in relation manager usi...
Package filament/spatie-laravel-translatable-plugin Package Version v3.0.57 Laravel Version v10.24.0 Livewire Version v3.0.5 PHP Version PHP 8.1.1 Problem description When attempting to save record...
RobinDev
RobinDevβ€’8mo ago
Ill see if i can get it fixed, and if so, file a pr
Dan Harrin
Dan Harrinβ€’8mo ago
okay, yes that issue looks fine was this ever a feature? the translatable plugin has always been very basic
RobinDev
RobinDevβ€’8mo ago
Yes with v2 it worked, fine, with v3 almost all translationatable things are broken Probably just a simple thing that changed or something, but i holds me to upgrade. My own features are custom and worked. before. But even translatable repeaters/relationships dont work anymore I would be able to give you access to a repo where you can test this easily Would i need to fix it in the translatable plugin, or in filament self?
Dan Harrin
Dan Harrinβ€’8mo ago
probably in filament itself in the translatablecontentdriver thing
RobinDev
RobinDevβ€’8mo ago
Do you have an idea where this happens?
No description
RobinDev
RobinDevβ€’8mo ago
Found the problem in the spatie laravel translatable content driver, the code from the image below, in the query there are backticks added, which causes the error.
No description
RobinDev
RobinDevβ€’8mo ago
Fixed it: default => should be
default => "JSON_UNQUOTE(JSON_EXTRACT(`{$column}`, '$.{$this->activeLocale}'))",
default => "JSON_UNQUOTE(JSON_EXTRACT(`{$column}`, '$.{$this->activeLocale}'))",
in file SpatieLaravelTranslatableDriver
LeandroFerreira
LeandroFerreiraβ€’8mo ago
GitHub
Fix - Set record translations by leandrocfe Β· Pull Request #9633 Β· ...
Fixed - #8656 Changes have been thoroughly tested to not break existing functionality. New functionality has been documented or existing documentation has been updated to reflect changes. Visua...
RobinDev
RobinDevβ€’8mo ago
What does this fix exactly? Not all problems does it?
RobinDev
RobinDevβ€’8mo ago
Ill test it and confirm oke?
LeandroFerreira
LeandroFerreiraβ€’8mo ago
Please
RobinDev
RobinDevβ€’8mo ago
No description
LeandroFerreira
LeandroFerreiraβ€’8mo ago
GitHub
filament/packages/support/src/helpers.php at 3.x Β· filamentphp/fila...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
RobinDev
RobinDevβ€’8mo ago
3.0.8 This one
Dan Harrin
Dan Harrinβ€’8mo ago
we are on 3.0.93 now there were lots of translatable issues when we first released v3 but most of those are now fixed
RobinDev
RobinDevβ€’8mo ago
I probably sound stupid now, but is this incorrect then?
"filament/filament": "^3.0"
"filament/filament": "^3.0"
LeandroFerreira
LeandroFerreiraβ€’8mo ago
did you run composer update?
RobinDev
RobinDevβ€’8mo ago
Yup
LeandroFerreira
LeandroFerreiraβ€’8mo ago
share the composer.json
RobinDev
RobinDevβ€’8mo ago
LeandroFerreira
LeandroFerreiraβ€’8mo ago
remove "filament/forms": "^3.0" and run composer update
RobinDev
RobinDevβ€’8mo ago
Still same
LeandroFerreira
LeandroFerreiraβ€’8mo ago
"laravel/framework": "^9.19" ?
RobinDev
RobinDevβ€’8mo ago
Ahg i see, lemme fix that now
Dan Harrin
Dan Harrinβ€’8mo ago
also "minimum-stability": "stable",
RobinDev
RobinDevβ€’8mo ago
Got it now, in the .json This does not work yet
RobinDev
RobinDevβ€’8mo ago
No description
RobinDev
RobinDevβ€’8mo ago
No description
Dan Harrin
Dan Harrinβ€’8mo ago
it never did we have never had a feature that translates select options
RobinDev
RobinDevβ€’8mo ago
But we should be able to fix this right? It was more as a reply to leandro if not, ill just fix this with the getStateUsing function
Dan Harrin
Dan Harrinβ€’8mo ago
->getOptionLabelFromRecordUsing(fn ($record) => $record->name) is prob right
RobinDev
RobinDevβ€’8mo ago
Yes! Im going to test repeaters now
LeandroFerreira
LeandroFerreiraβ€’8mo ago
GitHub
filament/packages/spatie-laravel-translatable-plugin/src/SpatieLara...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
RobinDev
RobinDevβ€’8mo ago
Yeah i filled my local file with this so i can test it, searching translated fields in the table does not work yet, but i have a fix for that
RobinDev
RobinDevβ€’8mo ago
Hmmm, does not work i see: https://share.cleanshot.com/4RwgpxB6
CleanShot Cloud
CleanShot 2023-11-14 at 11.42.06
Video uploaded to CleanShot Cloud
LeandroFerreira
LeandroFerreiraβ€’8mo ago
If you want, share your repo. I can have a look
RobinDev
RobinDevβ€’8mo ago
Can you maybe check the video? When i save when set to english, it just saves the dutch version to 'en'
LeandroFerreira
LeandroFerreiraβ€’8mo ago
GitHub
GitHub - tlegenbayangali/filament-repeater-translatable-issue
Contribute to tlegenbayangali/filament-repeater-translatable-issue development by creating an account on GitHub.
RobinDev
RobinDevβ€’8mo ago
i could give you access, can you give me a github username
LeandroFerreira
LeandroFerreiraβ€’8mo ago
leandrocfe@gmail.com
RobinDev
RobinDevβ€’8mo ago
Addede i see this is done with a relationManager, and not a repeater right?
LeandroFerreira
LeandroFerreiraβ€’8mo ago
yes I cant reproduce your test because your repo isn't updated please create a branch with your resource test, composer updates, etc..
RobinDev
RobinDevβ€’8mo ago
its updated now haha You can pull and edit master Excuse me, i forgot it haha but fixed now
LeandroFerreira
LeandroFerreiraβ€’8mo ago
sorry, I can't test it. The project has migrations issues, this doesn't have seeders... I can help you, but you can provide a repo that I can test
RobinDev
RobinDevβ€’8mo ago
Let me fix that for you You can pull now, when you do a fresh migrate you can login with robin@dashed.nl & 123123 And then you can test this by create a Test at the TestResource Can you test the function below, in the same file, this fixes the translatable search in tabels
public function applySearchConstraintToQuery(Builder $query, string $column, string $search, string $whereClause, ?bool $isCaseInsensitivityForced = null): Builder
{
/** @var Connection $databaseConnection */
$databaseConnection = $query->getConnection();

$column = match ($databaseConnection->getDriverName()) {
'pgsql' => "{$column}->>'{$this->activeLocale}'",
default => "JSON_UNQUOTE(JSON_EXTRACT(`{$column}`, '$.{$this->activeLocale}'))",
};

return $query->{$whereClause}(
new Expression(generate_search_column_expression($column, $isCaseInsensitivityForced, $databaseConnection)),
'like',
"%{$search}%",
);
}
public function applySearchConstraintToQuery(Builder $query, string $column, string $search, string $whereClause, ?bool $isCaseInsensitivityForced = null): Builder
{
/** @var Connection $databaseConnection */
$databaseConnection = $query->getConnection();

$column = match ($databaseConnection->getDriverName()) {
'pgsql' => "{$column}->>'{$this->activeLocale}'",
default => "JSON_UNQUOTE(JSON_EXTRACT(`{$column}`, '$.{$this->activeLocale}'))",
};

return $query->{$whereClause}(
new Expression(generate_search_column_expression($column, $isCaseInsensitivityForced, $databaseConnection)),
'like',
"%{$search}%",
);
}
i think we miss something for the repeaters in Resources > Pages > EditRecord > Concerns > Translatable But when i add the relationship name to the $translatable array in the model, it does work πŸ™‚
LeandroFerreira
LeandroFerreiraβ€’8mo ago
yes, this is working, right?
RobinDev
RobinDevβ€’8mo ago
Yes! im going to test this in my big project right now to see if that works too Can you implement my code too?
LeandroFerreira
LeandroFerreiraβ€’8mo ago
send a pr please
RobinDev
RobinDevβ€’8mo ago
It is combined with your code so how do i do that? (i never did that before)
LeandroFerreira
LeandroFerreiraβ€’8mo ago
I think you can fork the repo and go to gh pr checkout 9633
RobinDev
RobinDevβ€’8mo ago
Forked it, and cloned it, but this error
No description
RobinDev
RobinDevβ€’8mo ago
Nvm got it
RobinDev
RobinDevβ€’8mo ago
GitHub
Fix - Fixed translatable form search by Robinvm Β· Pull Request #964...
Fixed - #8656 Changes have been thoroughly tested to not break existing functionality. New functionality has been documented or existing documentation has been updated to reflect changes. Visua...
RobinDev
RobinDevβ€’8mo ago
Can you check if this is okay? i notice the builder doesnt work either, with blocks in them, they glitch when saving the second translation i have the code below but those functions dont get called when switching locale
Group::make()
->schema($schema)
->columns(2)
->columnSpanFull()
->visible(fn ($livewire) => count($schema) && !$livewire instanceof CreateRecord)
->relationship('customBlocks')
->mutateRelationshipDataBeforeCreateUsing(function ($data, $livewire) {
ray('mutateRelationshipDataBeforeCreateUsing');
$blocks = [];
foreach ($data as $key => $item) {
$blocks[$key] = $item;
unset($data[$key]);
}
$data['blocks'][$livewire->activeLocale] = $blocks;

return $data;
})
->mutateRelationshipDataBeforeSaveUsing(function ($data, $livewire) {
ray('mutateRelationshipDataBeforeSaveUsing');
$blocks = $livewire->record->blocks ?: [];
foreach ($data as $key => $item) {
$blocks[$key] = $item;
unset($data[$key]);
}
$data['blocks'][$livewire->activeLocale] = $blocks;

return $data;
})
->mutateRelationshipDataBeforeFillUsing(function ($data) {
ray('mutateRelationshipDataBeforeFillUsing');
if (is_array($data['blocks'])) {
foreach ($data['blocks'] ?? [] as $key => $item) {
$data[$key] = $item;
}
}

return $data;
}),
Group::make()
->schema($schema)
->columns(2)
->columnSpanFull()
->visible(fn ($livewire) => count($schema) && !$livewire instanceof CreateRecord)
->relationship('customBlocks')
->mutateRelationshipDataBeforeCreateUsing(function ($data, $livewire) {
ray('mutateRelationshipDataBeforeCreateUsing');
$blocks = [];
foreach ($data as $key => $item) {
$blocks[$key] = $item;
unset($data[$key]);
}
$data['blocks'][$livewire->activeLocale] = $blocks;

return $data;
})
->mutateRelationshipDataBeforeSaveUsing(function ($data, $livewire) {
ray('mutateRelationshipDataBeforeSaveUsing');
$blocks = $livewire->record->blocks ?: [];
foreach ($data as $key => $item) {
$blocks[$key] = $item;
unset($data[$key]);
}
$data['blocks'][$livewire->activeLocale] = $blocks;

return $data;
})
->mutateRelationshipDataBeforeFillUsing(function ($data) {
ray('mutateRelationshipDataBeforeFillUsing');
if (is_array($data['blocks'])) {
foreach ($data['blocks'] ?? [] as $key => $item) {
$data[$key] = $item;
}
}

return $data;
}),
with the builder and group relationships in the form builder i still have the issue that when i want to save another language than the default one, the fields get cleared out. Do you have any idea where i can catch this to fix this? Id love to fix it and PR it.
RobinDev
RobinDevβ€’8mo ago
CleanShot Cloud
CleanShot 2023-11-14 at 16.19.12
Video uploaded to CleanShot Cloud
LeandroFerreira
LeandroFerreiraβ€’8mo ago
open an issue with a repo to reproduce it or send a PR
RobinDev
RobinDevβ€’8mo ago
Dan is going to look into it soon, will create a repo tomorrow too
MeTi
MeTiβ€’8mo ago
I am experiencing the same issue. Have you been able to resolve it or find a solution? The project is urgent, and the project manager is frustrated @RobinDev @Leandro Ferreira
RobinDev
RobinDevβ€’8mo ago
Its fixed
LeandroFerreira
LeandroFerreiraβ€’8mo ago
Filament version?
MeTi
MeTiβ€’8mo ago
how? v3.0.102 last version
LeandroFerreira
LeandroFerreiraβ€’8mo ago
What is the issue? Could you share the code please?
Dan Harrin
Dan Harrinβ€’8mo ago
for someone with an urgent issue you arent giving anyone much to work with πŸ˜‚
MeTi
MeTiβ€’8mo ago
same as this i replied to @Leandro Ferreira
LeandroFerreira
LeandroFerreiraβ€’8mo ago
Share the code
MeTi
MeTiβ€’8mo ago
give me your github username
LeandroFerreira
LeandroFerreiraβ€’8mo ago
leandrocfe@gmail.com
MeTi
MeTiβ€’8mo ago
i sent invite
MeTi
MeTiβ€’8mo ago
its in ProductResource.php
No description
LeandroFerreira
LeandroFerreiraβ€’8mo ago
add in the Product model
public $translatable = ['name', 'description', 'options']
public $translatable = ['name', 'description', 'options']
MeTi
MeTiβ€’8mo ago
Oooooooo mannnn thank you so much i cant belive all was this
LeandroFerreira
LeandroFerreiraβ€’8mo ago
good news for the project manager
MeTi
MeTiβ€’8mo ago
yeah i was planing to remove multi lang featureπŸ˜‚
LeandroFerreira
LeandroFerreiraβ€’8mo ago
it would work as well πŸ˜…
MeTi
MeTiβ€’8mo ago
Yeah!! I believe it would be good to include this information in the package documentation. It's possible that others, like myself, may encounter a similar bug.
LeandroFerreira
LeandroFerreiraβ€’8mo ago
You can send a PR πŸ‘
Daniel Plomp
Daniel Plompβ€’8mo ago
@RobinDev Question: how did you do this in the sidebar?
No description
Dennis Koch
Dennis Kochβ€’8mo ago
What is "this'"?
Daniel Plomp
Daniel Plompβ€’8mo ago
πŸ™‚ Fair enough. I meant how can you create these levels in the menu? Like a hierarchy?
Dennis Koch
Dennis Kochβ€’8mo ago
It's probably a group with 3 items, where one doesn't have an Icon. I thought this only works completely without icons, tohug.
Want results from more Discord servers?
Add your server
More Posts