## 問題
seedファイル、ツリー構造という記事を参考にしてツリー構造のデータを作成しようとしていますがうまくいきません。
上記のエラー分が出てしまう原因を教えていただきたいです。
laravel-nestedset使用
php
1MapTableSeeder.php 2<?php 3 4use Illuminate\Database\Seeder; 5 6class MapTableSeeder extends Seeder 7{ 8 /** 9 * Run the database seeds. 10 * 11 * @return void 12 */ 13 public function run() 14 { 15 $maps = [ 16 [ 17 'name' => '銀行', 18 'path' => 'images/maps_top/bank.jpg', 19 'children' => [ 20 [ 21 ['path' => 'images/maps/bank/bank_1.jpg'], 22 ['path' => 'images/maps/bank/bank_2.jpg'], 23 ['path' => 'images/maps/bank/bank_3.jpg'], 24 ['path' => 'images/maps/bank/bank_4.jpg'], 25 ], 26 ], 27 ], 28 [ 29 'name' => '国境', 30 'path' => 'images/maps_top/border.jpg', 31 'children' => [ 32 [ 33 ['path' => 'images/maps/border/border_1.jpg'], 34 ['path' => 'images/maps/border/border_2.jpg'], 35 ['path' => 'images/maps/border/border_3.jpg'], 36 ], 37 ], 38 ], 39 [ 40 'name' => 'カフェ・ドフトエスキー', 41 'path' => 'images/maps_top/cafe.jpg', 42 'children' => [ 43 [ 44 ['path' => 'images/maps/cafe/cafe_1.jpg'], 45 ['path' => 'images/maps/cafe/cafe_2.jpg'], 46 ['path' => 'images/maps/cafe/cafe_3.jpg'], 47 ['path' => 'images/maps/cafe/cafe_4.jpg'], 48 ], 49 ], 50 ], 51 52 53 ]; 54 55 foreach($maps as $map){ 56 57 \App\Models\Map_Category::create($map); 58 } 59} 60} 61
php
1DatabaseSeeder.php 2<?php 3 4use Illuminate\Database\Seeder; 5 6class DatabaseSeeder extends Seeder 7{ 8 /** 9 * Seed the application's database. 10 * 11 * @return void 12 */ 13 public function run() 14 { 15 // $this->call(UserSeeder::class); 16 $this->call(MapTableSeeder::class); 17 } 18}
php
1mapマイグレーション 2<?php 3 4use Illuminate\Database\Migrations\Migration; 5use Illuminate\Database\Schema\Blueprint; 6use Illuminate\Support\Facades\Schema; 7 8class CreateMapCategoriesTable extends Migration 9{ 10 /** 11 * Run the migrations. 12 * 13 * @return void 14 */ 15 public function up() 16 { 17 Schema::create('map__categories', function (Blueprint $table) { 18 $table->id(); 19 $table->string('name',40);//マップ名の入力のため 20 $table->string('path'); 21 $table->nestedSet(); 22 $table->timestamps(); 23 }); 24 } 25 26 /** 27 * Reverse the migrations. 28 * 29 * @return void 30 */ 31 public function down() 32 { 33 Schema::dropIfExists('map__categories'); 34 } 35 36} 37
エラー文
ErrorException Array to string conversion at vendor/laravel/framework/src/Illuminate/Support/Str.php:449 445| 446| $result = array_shift($segments); 447| 448| foreach ($segments as $segment) { > 449| $result .= (array_shift($replace) ?? $search).$segment; 450| } 451| 452| return $result; 453| } +19 vendor frames 20 database/seeds/MapTableSeeder.php:180 Illuminate\Database\Eloquent\Model::__callStatic("create") +8 vendor frames 29 database/seeds/DatabaseSeeder.php:15 Illuminate\Database\Seeder::call("MapTableSeeder") コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/16 11:01