首页 > 解决方案 > Laravel 播种机卡住并返回ErrorException 数组哟字符串转换

问题描述

public function up()
{
    Schema::create('settings', function (Blueprint $table) {
        $table->id();
        $table->string('name', 40)->unique();
        $table->json('value');
        $table->timestamps();
    });

    //seeder to insert FTP settings
    DB::table("settings")->insert([
        'name' => 'FTP_SETTINGS',
        'value' => ['host' => '192.168.5.190', 'username'=> 'Alessandro', 'password' => 'Alessandro', 'port' => '21']
    ]);
}

之后我正在使用播种机进行此迁移(我也将其放入播种机部分,但有同样的问题),但我得到了 ErrorException 数组到字符串的转换。可能是具有价值的东西,但我无法理解我做错了什么......非常感谢您的帮助。

标签: laraveleloquentlaravel-migrationslaravel-seeding

解决方案


您正在尝试将数组值插入到 json 文件中。

Try instead: 

    DB::table("settings")->insert([
        'name' => 'FTP_SETTINGS',
        'value' => json_encode(['host' => '192.168.5.190', 'username'=> 'Alessandro', 'password' => 'Alessandro', 'port' => '21'])
    ]);

推荐阅读