Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 156 forks source link

Create Method with translations - SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' #257

Closed ekcltfrm closed 2 years ago

ekcltfrm commented 2 years ago

Hello and Happy New Year to all,

I am trying add my translations from request to my create method i'm getting this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list'

How can i pass the translation collection i am creating with that foreach loop to my create method data;

        $data = collect();
        foreach ($locales as $locale) {
            $data[$locale->isocode] =
            [
                'name' => $request->input("name:$locale->isocode"),
            ];
        }

        $item= Item::create([
            $data,
            'customer_id' => $customer->id,
            'user_id' => $user->id,
            'abc_id' => $abc->id,
            'project_id' => $project->id,

            'tax_rate' => $request->input('tax_rate'),
            'quantity' => $request->input('quantity'),
            'unitprice' => $request->input('unitprice'),
        ]);

What would be the correct way to save initial model data with translations (rather than first creating the data in a local then creating form to update translations, i am already doing that) ?

ekcltfrm commented 2 years ago

i was able to solve my issue with array_merge() function in my method.