duankeng9477 2017-05-28 03:29
浏览 115
已采纳

Laravel:播种数据库时出错(数组转换为字符串)

I'm trying to seed the database. Following the User example I create a Emploi (Job) seeder but I'm having an error.

seeding file

$factory->define(App\Emploi::class, function (Faker\Generator $faker) {

    return [
        'JOBURL' => $faker->name,
        'SALARYMAX' => '$50,000',
        'SALARYMIN' => '$40,000',
        'SALARYTYPE' => 'annual',
        'NAME' => $faker->words(5),
        'POSITION' => $faker->words(4),
        'JOBREF' => str_random(10),
        'JOB_SUMMARY' => $faker->text,
        'tweeted' => false,
        'POSTDATE' => $faker->dateTime(),
        'EXPIRYDATE' => $faker->dateTime(),
        'slug' => str_random(10),
    ];
});

exception

[ErrorException]
  Array to string conversion

output

 [Illuminate\Database\QueryException]
  Array to string conversion 
  (SQL: insert into `emplois` 

  (`JOBURL`, `SALARYMAX`, 
  `SALARYMIN`, `SALARYTYPE`, `NAME`, `POSITION`, 
  `JOBREF`, 
  `JOB_SUMMARY`, 
  `tweeted`, `
  POSTDATE`, `EXPIRYDATE`, `slug`, 
  `updated_at`, `created_at`) 
  values 
  (Lawson Boyer II, $50,000,
  $40,000, annual, rerum, voluptates, 
  LCw8d67S8w, 
  Nulla qui corporis sequi. 
  Eum nostrum culpa ut culpa velit. 
  Molestiae cumque doloremque et ex., 
  0, 
  1972-11-09 12:00:07, 1997-10-04 09:08:17, 6FxxCHFus6,
  2017-05-28 03:18:52, 2017-05-2  8 03:18:52)

  )

databaseSeeder

factory(App\Emploi::class, 50)->create();
  • 写回答

2条回答 默认 最新

  • dtjxhf595733 2017-05-28 03:45
    关注

    The Faker library has a few methods that'll return an array instead of a string. What laravel is expecting here is a string. So, you could either use PHP's implode function to create a string, or swap out the entire $faker->words() method for $faker->sentence(). Here's the method signature:

    sentence($nbWords = 6, $variableNbWords = true)

    Cheers!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制