Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Being able to access the translations from the UpdateOrCreate method #274

Open
cris-alteregoweb opened this issue Apr 7, 2022 · 1 comment

Comments

@cris-alteregoweb
Copy link

It would be nice to be able to access the translations in the condition of the updateOrCreate method just like when using it when doing insert. Something like that:

Model::updateOrCreate([ 'model_id' => $model->id, 'es' => [ 'section' => 'Ejemplo', 'title' => 'Ejemplo documento ', 'doc' => 'documento.pdf', ], ], [ 'model_id' => $model->id, 'es' => [ 'section' => 'Ejemplo', 'title' => 'Ejemplo documento', 'doc' => 'documento_es.pdf', ], 'en' => [ 'section' => 'Example', 'title' => 'Example document', 'doc' => 'document_en.pdf', ], ]);

I find myself in this problem and I thought it was a good idea to propose it.

@Lintume
Copy link

Lintume commented Nov 19, 2024

I found the hack (MySQL)
Instead of this format

$ia = $company->inspectionAttributes()->updateOrCreate([
                        'translatable_name' => [
                            'zh' => $rowProperties['translation zh'],
                            'en' => $rowProperties['translation english'],
                        ],
                    ], [
                        'unit' => $rowProperties['unit'],
                    ]);

use this:

$company->inspectionAttributes()->updateOrCreate([
                        'translatable_name->zh' => $rowProperties['translation zh'],
                        'translatable_name->en' => $rowProperties['translation english'],
                    ], [
                        'unit' => $rowProperties['unit'],
                    ]);

DO NOT FORGET to add to the model fillable property translatable_name->zh and translatable_name->en!
And updateOrCreate works correct!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants