我在laravel 5.3中使用模型工厂创建一个表播种器时出错,但我不知道我在哪里出错了。
[ErrorException] 传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须是数组,给定的字符串,在D:\ Coding \ php \ laravel \ simple-blog \ vendor \ laravel \ framework \ src \ Illuminate \ Database中调用在第660行查询\ Grammars \ Grammar.php并定义
这是我的代码:
型号:
<?php
namespace app;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $table = 'articles';
}
模型工厂:
$factory->define(app\Article::class, function (Faker\Generator $faker){
return [
'title' => $faker->sentences(5),
'content' => $faker->text(),
'created_at' => \Carbon\Carbon::now(),
'updated_at' => \Carbon\Carbon::now()
];
});
迁移:
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('content');
$table->timestamps();
});
}
ArticlesTableSeeder:
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Faker\Factory as Faker;
use app\Article as Article;
class ArticlesTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(Article::class)->create();
}
}
答案 0 :(得分:2)
'title' => $faker->sentences(5),
生成包含5个值的数组。返回之前创建var并将这些句子连接起来。
或sentences(5, true);
将为您生成5个句子文本。