F
Filamentβ€’13mo 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
RobinDevOPβ€’13mo ago
Is this fixed? @Dan Harrin Can i maybe help with this
Dan Harrin
Dan Harrinβ€’13mo 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
RobinDevOPβ€’13mo 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
RobinDevOPβ€’13mo ago
Ill see if i can get it fixed, and if so, file a pr
Dan Harrin
Dan Harrinβ€’13mo ago
okay, yes that issue looks fine was this ever a feature? the translatable plugin has always been very basic
RobinDev
RobinDevOPβ€’13mo 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β€’13mo ago
probably in filament itself in the translatablecontentdriver thing
RobinDev
RobinDevOPβ€’13mo ago
Do you have an idea where this happens?
No description
RobinDev
RobinDevOPβ€’13mo 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
RobinDevOPβ€’13mo 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β€’13mo 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
RobinDevOPβ€’13mo ago
What does this fix exactly? Not all problems does it?
RobinDev
RobinDevOPβ€’13mo ago
Ill test it and confirm oke?
LeandroFerreira
LeandroFerreiraβ€’13mo ago
Please
RobinDev
RobinDevOPβ€’13mo ago
No description
LeandroFerreira
LeandroFerreiraβ€’13mo 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
RobinDevOPβ€’13mo ago
3.0.8 This one
Dan Harrin
Dan Harrinβ€’13mo 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
RobinDevOPβ€’13mo ago
I probably sound stupid now, but is this incorrect then?
"filament/filament": "^3.0"
"filament/filament": "^3.0"
LeandroFerreira
LeandroFerreiraβ€’13mo ago
did you run composer update?
RobinDev
RobinDevOPβ€’13mo ago
Yup
LeandroFerreira
LeandroFerreiraβ€’13mo ago
share the composer.json
RobinDev
RobinDevOPβ€’13mo ago
LeandroFerreira
LeandroFerreiraβ€’13mo ago
remove "filament/forms": "^3.0" and run composer update
RobinDev
RobinDevOPβ€’13mo ago
Still same
LeandroFerreira
LeandroFerreiraβ€’13mo ago
"laravel/framework": "^9.19" ?
RobinDev
RobinDevOPβ€’13mo ago
Ahg i see, lemme fix that now
Dan Harrin
Dan Harrinβ€’13mo ago
also "minimum-stability": "stable",
RobinDev
RobinDevOPβ€’13mo ago
Got it now, in the .json This does not work yet
RobinDev
RobinDevOPβ€’13mo ago
No description
RobinDev
RobinDevOPβ€’13mo ago
No description
Dan Harrin
Dan Harrinβ€’13mo ago
it never did we have never had a feature that translates select options
RobinDev
RobinDevOPβ€’13mo 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β€’13mo ago
->getOptionLabelFromRecordUsing(fn ($record) => $record->name) is prob right
RobinDev
RobinDevOPβ€’13mo ago
Yes! Im going to test repeaters now
LeandroFerreira
LeandroFerreiraβ€’13mo 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
RobinDevOPβ€’13mo 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
RobinDevOPβ€’13mo 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β€’13mo ago
If you want, share your repo. I can have a look
RobinDev
RobinDevOPβ€’13mo ago
Can you maybe check the video? When i save when set to english, it just saves the dutch version to 'en'
LeandroFerreira
LeandroFerreiraβ€’13mo ago
GitHub
GitHub - tlegenbayangali/filament-repeater-translatable-issue
Contribute to tlegenbayangali/filament-repeater-translatable-issue development by creating an account on GitHub.
RobinDev
RobinDevOPβ€’13mo ago
i could give you access, can you give me a github username
RobinDev
RobinDevOPβ€’13mo ago
Addede i see this is done with a relationManager, and not a repeater right?
LeandroFerreira
LeandroFerreiraβ€’13mo 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
RobinDevOPβ€’13mo ago
its updated now haha You can pull and edit master Excuse me, i forgot it haha but fixed now
LeandroFerreira
LeandroFerreiraβ€’13mo 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
RobinDevOPβ€’13mo ago
Let me fix that for you You can pull now, when you do a fresh migrate you can login with [email protected] & 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β€’13mo ago
yes, this is working, right?
RobinDev
RobinDevOPβ€’13mo 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β€’13mo ago
send a pr please
RobinDev
RobinDevOPβ€’13mo ago
It is combined with your code so how do i do that? (i never did that before)
LeandroFerreira
LeandroFerreiraβ€’13mo ago
I think you can fork the repo and go to gh pr checkout 9633
RobinDev
RobinDevOPβ€’13mo ago
Forked it, and cloned it, but this error
No description
RobinDev
RobinDevOPβ€’13mo ago
Nvm got it
RobinDev
RobinDevOPβ€’13mo 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
RobinDevOPβ€’13mo 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
RobinDevOPβ€’13mo ago
CleanShot Cloud
CleanShot 2023-11-14 at 16.19.12
Video uploaded to CleanShot Cloud
LeandroFerreira
LeandroFerreiraβ€’13mo ago
open an issue with a repo to reproduce it or send a PR
RobinDev
RobinDevOPβ€’13mo ago
Dan is going to look into it soon, will create a repo tomorrow too
MeTi
MeTiβ€’13mo 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
RobinDevOPβ€’13mo ago
Its fixed
LeandroFerreira
LeandroFerreiraβ€’13mo ago
Filament version?
MeTi
MeTiβ€’13mo ago
how? v3.0.102 last version
LeandroFerreira
LeandroFerreiraβ€’13mo ago
What is the issue? Could you share the code please?
Dan Harrin
Dan Harrinβ€’13mo ago
for someone with an urgent issue you arent giving anyone much to work with πŸ˜‚
MeTi
MeTiβ€’13mo ago
same as this i replied to @Leandro Ferreira
LeandroFerreira
LeandroFerreiraβ€’13mo ago
Share the code
MeTi
MeTiβ€’13mo ago
give me your github username
MeTi
MeTiβ€’13mo ago
i sent invite
MeTi
MeTiβ€’13mo ago
its in ProductResource.php
No description
LeandroFerreira
LeandroFerreiraβ€’13mo ago
add in the Product model
public $translatable = ['name', 'description', 'options']
public $translatable = ['name', 'description', 'options']
MeTi
MeTiβ€’13mo ago
Oooooooo mannnn thank you so much i cant belive all was this
LeandroFerreira
LeandroFerreiraβ€’13mo ago
good news for the project manager
MeTi
MeTiβ€’13mo ago
yeah i was planing to remove multi lang featureπŸ˜‚
LeandroFerreira
LeandroFerreiraβ€’13mo ago
it would work as well πŸ˜…
MeTi
MeTiβ€’13mo 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β€’13mo ago
You can send a PR πŸ‘
Daniel Plomp
Daniel Plompβ€’12mo ago
@RobinDev Question: how did you do this in the sidebar?
No description
Dennis Koch
Dennis Kochβ€’12mo ago
What is "this'"?
Daniel Plomp
Daniel Plompβ€’12mo ago
πŸ™‚ Fair enough. I meant how can you create these levels in the menu? Like a hierarchy?
Dennis Koch
Dennis Kochβ€’12mo 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