Astrotomic / laravel-translatable

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

Filling multiple translations error #337

Closed StrangerGithuber closed 1 year ago

StrangerGithuber commented 1 year ago

Hi, I am trying to add multiple records in the same time but I get errors:

I am using this in the seeder class:

 $menus = [
            [
                'type' => 'Admin Sidebar',
                'isroute' => 1,
                'icon' => 'fa fa-tachometer-alt',
                'sort_order' => 0,
                'en' => ['name' => 'Dashboard', 'slug' => 'admindashboard'],
                'hu' => ['name' => 'Irányítópult', 'slug' => 'admindashboard'],
                'pl' => ['name' => 'Panel', 'slug' => 'admindashboard'],
                'sv' => ['name' => 'Dashboard', 'slug' => 'admindashboard'],
            ],
            [
                'type' => 'Admin Sidebar',
                'isroute' => 1,
                'icon' => 'fa fa-th',
                'sort_order' => 1,
                'en' => ['name' => 'Projects', 'slug' => 'adminprojects'],
                'hu' => ['name' => 'Projektek', 'slug' => 'adminprojects'],
                'pl' => ['name' => 'Projektowanie', 'slug' => 'adminprojects'],
                'sv' => ['name' => 'Projekt', 'slug' => 'adminprojects'],
            ],
            [
                'type' => 'Admin Sidebar',
                'isroute' => 1,
                'icon' => 'fas fa-book',
                'sort_order' => 2,
                'en' => ['name' => 'Categories', 'slug' => 'admincatmanager'],
                'hu' => ['name' => 'Kategóriák', 'slug' => 'admincatmanager'],
                'pl' => ['name' => 'Kategorie', 'slug' => 'admincatmanager'],
                'sv' => ['name' => 'Kategorier', 'slug' => 'admincatmanager'],
            ],
            [
                'type' => 'Admin Sidebar',
                'isroute' => 1,
                'icon' => 'fas fa-compass',
                'sort_order' => 3,
                'en' => ['name' => 'Menus', 'slug' => 'adminmenus'],
                'hu' => ['name' => 'Menűk', 'slug' => 'adminmenus'],
                'pl' => ['name' => 'Kategorie', 'slug' => 'adminmenus'],
                'sv' => ['name' => 'Kategorier', 'slug' => 'adminmenus'],
            ],
            [
                'type' => 'Frontend Menu',
                'isroute' => 1,
                'icon' => 'fas fa-home',
                'sort_order' => 0,
                'en' => ['name' => 'Home', 'slug' => 'home'],
                'hu' => ['name' => 'Kezdőlap', 'slug' => 'home'],
                'pl' => ['name' => 'Główne', 'slug' => 'home'],
                'sv' => ['name' => 'Hem', 'slug' => 'home'],
            ],
            [
                'type' => 'Frontend Menu',
                'isroute' => 1,
                'icon' => 'fas fa-project-diagram',
                'sort_order' => 1,
                'en' => ['name' => 'Projects', 'slug' => 'projects'],
                'hu' => ['name' => 'Projektek', 'slug' => 'projects'],
                'pl' => ['name' => 'Projektowanie', 'slug' => 'projects'],
                'sv' => ['name' => 'Projekt', 'slug' => 'projects'],
            ],
            [
                'type' => 'Frontend Menu',
                'isroute' => 1,
                'icon' => 'fas fa-hand-holding-usd',
                'sort_order' => 2,
                'en' => ['name' => 'Donation', 'slug' => 'donation'],
                'hu' => ['name' => 'Támogatás', 'slug' => 'donation'],
                'pl' => ['name' => 'Darowizna', 'slug' => 'donation'],
                'sv' => ['name' => 'Donation', 'slug' => 'donation'],
            ],
            [
                'type' => 'Frontend Menu',
                'isroute' => 1,
                'icon' => 'fas fa-hand-holding-usd',
                'sort_order' => 3,
                'en' => ['name' => 'About Us', 'slug' => 'donation'],
                'hu' => ['name' => 'Rólunk', 'slug' => 'donation'],
                'pl' => ['name' => 'O nas', 'slug' => 'donation'],
                'sv' => ['name' => 'Om oss', 'slug' => 'donation'],
            ],
        ];

foreach ($menus as $menu) {
            Menu::create($menu);
        }

Error message:

php artisan db:seed --class=MenuSeeder

   INFO  Seeding database.

   ErrorException 

  Array to string conversion

  at C:\laragon\www\xxx\vendor\laravel\framework\src\Illuminate\Support\Str.php:864
    860▕
    861▕         $result = array_shift($segments);
    862▕
    863▕         foreach ($segments as $segment) {
  ➜ 864▕             $result .= (array_shift($replace) ?? $search).$segment;
    865▕         }
    866▕
    867▕         return $result;
    868▕     }

  1   C:\laragon\www\xxx\vendor\laravel\framework\src\Illuminate\Support\Str.php:864
      Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("Array to string conversion", "C:\laragon\www\xxx\vendor\laravel\framework\src\Illuminate\Support\Str.php")

  2   C:\laragon\www\xxx\vendor\laravel\framework\src\Illuminate\Database\QueryException.php:67
      Illuminate\Support\Str::replaceArray("?", "insert into `menus` (`type`, `isroute`, `icon`, `sort_order`, `en`, `hu`, `pl`, `sv`, `id`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")

I did using this tutorial: https://docs.astrotomic.info/laravel-translatable/

So what I am doing wrong then? Thanks in advance the answers.

StrangerGithuber commented 1 year ago

If I delete en, hu, pl and sv array keys and values then the seed will be executed normally. Then the documentation is wrong or I am missing something. Did someone else success to use that example from the documentation?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days

matinwd commented 1 year ago

Same here.. Any updates? is it deprecated in newer versions or other reasons

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days

Dezmonter commented 10 months ago

I am getting the same error!