1
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.

aimme
  • 6,385
  • 7
  • 48
  • 65
  • your value is not a string rather another array ['host' => '......', 'username'.......... ]. it should be a string – Farhan Ibn Wahid Apr 09 '21 at 09:45
  • Instead `'value' => ['host' => '192.168.5.190', 'username'=> 'Alessandro', 'password' => 'Alessandro', 'port' => '21']` you can think to either save all in different columns or do `'value' => json_encode(['host' => '192.168.5.190', 'username'=> 'Alessandro', 'password' => 'Alessandro', 'port' => '21'])` – Prafulla Kumar Sahu Apr 09 '21 at 09:51

1 Answers1

1

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'])
    ]);
N L
  • 145
  • 9