Reputation: 161
I get an error when create a table seeder using model factory in laravel 5.3 but I don't know where I'm going wrong here.
[ErrorException] Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given, called in D:\Coding\php\laravel\simple-blog\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 660 and defined
Here is my code:
Model:
<?php
namespace app;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $table = 'articles';
}
Model Factory:
$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()
];
});
Migrations:
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();
}
}
Upvotes: 0
Views: 801
Reputation: 3710
'title' => $faker->sentences(5),
produces array with 5 values. Make var before return and concat there these sentences.
Or sentences(5, true);
Will produce 5 sentence text for you.
Upvotes: 3