Closed shahmal1yev closed 3 years ago
use App\Models\Category\Category; $data = [ 'en' => ['name' => 'Shirt'], 'fr' => ['name' => 'La chemise'] ]; Category::create($data);
use App\Models\Category\Category;
$data = [ 'en' => ['name' => 'Shirt'], 'fr' => ['name' => 'La chemise'] ];
Category::create($data);
App\Models\Category\Category {#4268 id: 20, translations: Illuminate\Database\Eloquent\Collection {#4113 all: [ App\Models\Category\CategoryTranslation {#4270 locale: "en", name: "Shirt", category_id: 20, id: 13, }, App\Models\Category\CategoryTranslation {#4180 locale: "fr", name: "La chemise", category_id: 20, id: 14, }, ], }, }
There is no problem with the above Let's try this now.
$data = [ 'az' => ['name' => 'Köynək'], 'ru' => ['name' => 'Рубашка'] ]
`PHP Notice: Array to string conversion in C:\xampp\htdocs\feeles\vendor\laravel\framework\src\Illuminate\Support\Str.php on line 524
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list' (SQL: insert into categories (name) values (Array), (Array))'`
categories
name
Source of error
public static function replaceArray($search, array $replace, $subject) { $segments = explode($search, $subject); $result = array_shift($segments); foreach ($segments as $segment) { $result .= (array_shift($replace) ?? $search).$segment; } return $result; }
Line of Error:
$result .= (array_shift($replace) ?? $search).$segment;
The error stems from the code of Azerbaijan ("az"). And the codes of other languages ("ru", etc.)
Can you help, please?
Hey, have you defined your locales in the config? https://docs.astrotomic.info/laravel-translatable/installation#configuration
I accidentally skipped it. Thank you so much
use App\Models\Category\Category;
$data = [ 'en' => ['name' => 'Shirt'], 'fr' => ['name' => 'La chemise'] ];
Category::create($data);
App\Models\Category\Category {#4268 id: 20, translations: Illuminate\Database\Eloquent\Collection {#4113 all: [ App\Models\Category\CategoryTranslation {#4270 locale: "en", name: "Shirt", category_id: 20, id: 13, }, App\Models\Category\CategoryTranslation {#4180 locale: "fr", name: "La chemise", category_id: 20, id: 14, }, ], }, }
There is no problem with the above Let's try this now.
$data = [ 'az' => ['name' => 'Köynək'], 'ru' => ['name' => 'Рубашка'] ]
Category::create($data);
`PHP Notice: Array to string conversion in C:\xampp\htdocs\feeles\vendor\laravel\framework\src\Illuminate\Support\Str.php on line 524
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list' (SQL: insert into
categories
(name
) values (Array), (Array))'`Source of error
public static function replaceArray($search, array $replace, $subject) { $segments = explode($search, $subject); $result = array_shift($segments); foreach ($segments as $segment) { $result .= (array_shift($replace) ?? $search).$segment; } return $result; }
Line of Error:
$result .= (array_shift($replace) ?? $search).$segment;
The error stems from the code of Azerbaijan ("az"). And the codes of other languages ("ru", etc.)
Can you help, please?