Search code examples
laraveleloquentlaravel-migrationslaravel-seeding

Laravel seeder gets stuck and returns ErrorException Array yo string conversion


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

I'm doing this migration with a seeder after that (I've also put it into the seeder section but has the same issue) but i get the ErrorException Array to string conversion. Probably is something with the value propriety but I cannot understand what I'm doing wrong..many thanks for your help.


Solution

  • You are trying to insert array values into json filed.

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