Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel seeder被卡住并返回ErrorException数组yo字符串转换_Laravel_Eloquent_Laravel Migrations_Laravel Seeding - Fatal编程技术网

Laravel seeder被卡住并返回ErrorException数组yo字符串转换

Laravel seeder被卡住并返回ErrorException数组yo字符串转换,laravel,eloquent,laravel-migrations,laravel-seeding,Laravel,Eloquent,Laravel Migrations,Laravel Seeding,在那之后,我用一个seeder进行迁移(我也把它放在seeder部分,但有同样的问题),但是我得到了ErrorException数组到字符串的转换。 可能是值的适当性问题,但我无法理解我做错了什么。非常感谢您的帮助。您正在尝试将数组值插入json字段 public function up() { Schema::create('settings', function (Blueprint $table) { $table->id(); $table-

在那之后,我用一个seeder进行迁移(我也把它放在seeder部分,但有同样的问题),但是我得到了ErrorException数组到字符串的转换。
可能是值的适当性问题,但我无法理解我做错了什么。非常感谢您的帮助。

您正在尝试将数组值插入json字段

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']
    ]);
}

您的值不是一个字符串,而是另一个数组['host'=>'…','username'..]。它应该是字符串而不是
'value'=>['host'=>'192.168.5.190','username'=>'Alessandro','password'=>'Alessandro','port'=>'21']
您可以考虑将所有内容保存在不同的列中,或者执行
'value'=>json\u编码(['host'=>'192.168.5.190','username'=>'Alessandro','password'=>'Alessandro','port'=>'21'])
Try instead: 

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