mysql - 在mysql数据库laravel中保存多个整数

标签 mysql database laravel integer

当我尝试将数据保存到数据库中时,由于某种原因我只能保存 1 个整数,而不能保存多个整数。谁能告诉我为什么?我想这可能是因为我在数据库中使用 FamilyAge 作为整数而不是字符串。

这是我数据库中数据的屏幕截图,对于我输入的奇怪数据感到抱歉,我只是输入一些随机单词进行测试。 正如您在我的屏幕截图中看到的,最后一行,我应该保存 3 个数据,但对于家庭年龄部分,仅保存 1 个数据。 enter image description here

family_info Controller (这就是我保存它的方式)

public function submit(Request $request)
{

  $personal_info = Session::get('data');

  $data7 = array();
  $data7['NameOfFamily'] = implode(' , ', $request->NameOfFamily);
  $data7['Relationship'] = implode(' , ', $request->Relationship);
  $data7['FamilyAge'] = implode(' , ', $request->FamilyAge);
  $family_info = new family_info;
  $family_info = family_info::create($data7);
  $family_info->personal_infos()->associate($personal_info);
  $family_info->save();

}

familyInfos 表:

Schema::create('family_infos', function (Blueprint $table) {
    $table->increments('id');
    $table->engine = 'InnoDB';  
    $table->string('NameOfFamily');
    $table->string('Relationship'); 
    $table->integer('FamilyAge');
    $table->integer('user_id');
    $table->timestamps();
});

最佳答案

通过查看您的架构,您正在为 FamilyAge 使用整数类型 $table->integer('FamilyAge'); ,它应该是一个用于存储逗号分隔值的字符串 $table->string('FamilyAge');

我想你是想像这样22,45,56来挽救家庭年龄

Schema::create('family_infos', function (Blueprint $table) {
    $table->increments('id');
    $table->engine = 'InnoDB';  
    $table->string('NameOfFamily');
    $table->string('Relationship'); 
    $table->string('FamilyAge');
    $table->integer('user_id');
    $table->timestamps();
});

I recommend you to read this https://laravel.com/docs/5.5/migrations#columns which explains how to create the Laravel migration

关于mysql - 在mysql数据库laravel中保存多个整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47148183/

相关文章:

laravel - 为什么我不能成功运行 npm run dev?

php - 无法使用 000webhost 在 Laravel 中迁移

PHP 注册表未将用户添加到数据库

php - 在mysqli中把这行代码改成什么

php - 从数据库中旋转图像并保存到数据库 blob 类型

php - 忽略更新功能 Laravel 5 的唯一验证

mysql - SQL:选择多行两列的总和

MySQL - 在多次插入时使用最后插入的 ID

database - Cassandra等数据库需要Bloom Filter

PHP - DynamoDB - 唯一键