大佬教程收集整理的这篇文章主要介绍了php-使用属于用户的任务播种数据库,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
scheR_64_11845@a::create('tasks', function (Blueprint $tablE) {
$table->increments('id');
$table->String('name');
$table->Integer('@R_673_6528@d')->unsigned();
$table->timestamps();
});
@H_801_0@在TaskTableSeeder类中,我想为每个用户分配一些任务.class TaskTableSeeder extends Seeder
{
public function run()
{
$faker = Faker\Factory::create();
$limit = 25;
$userIds = DB::table('users')->get('id');
for ($i = 0; $i < $limit; $i++) {
DB::table('tasks')->insert([
'name' => $faker->sentence(),
'@R_673_6528@d' => $faker->randomElement($userIds),
]);
}
}
}
@H_801_0@但是,出现以下错误:
@H_801_0@
seeding: UserTableSeeder
seeding: TaskTableSeeder
In GrAMMar.PHP line 124:
Type error: Argument 1 passed to Illuminate\Database\GrAMMar::columnize() must be of the type array, String given, call
ed in C:\Users\marcus\Desktop\Coding Projects\demo_laravel_todo\vendor\laravel\framework\src\Illuminate\Database\Query\
GrAMMars\GrAMMar.PHP on line 131
@H_801_0@有什么建议我做错了吗?解决方法:
@H_801_0@因为将字符串传递给randomElement(),所以得到了错误.您需要将数组传递给randomElement(),因此请使用pluck()和toArray(): @H_801_0@$userIds = DB::table('users')->pluck('id')->toArray();
以上是大佬教程为你收集整理的php-使用属于用户的任务播种数据库全部内容,希望文章能够帮你解决php-使用属于用户的任务播种数据库所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。