An error occurred when using tinker to generate a test today
Write more details and wait for the expert to answer why the error occurred
I used migrate to generate the data table
public function up()
{
Schema::create('notice', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('content');
$table->integer('user_id')->default('0');
$table->timestamps();
});
}
Then my model is
php artisan make:model Models/Notice
Models/Notice.php only writes
in the modelprotected $table = 'notice';
protected $fillable = ['title','content'];
ModelFactory.php is like this
$factory->define(App\Models\Notice::class, function (Faker\Generator $faker) {
return [
'title' => $faker->sentences,
'content' => $faker->paragraph,
];
});
怪我咯2017-05-16 16:53:31
It should be something wrong in Modelfactory.php.
'title' => $faker->sentences,
改为
'title' => $faker->sentence,
$faker->sentences generates an array. You can judge based on the error message. For details, you can take a look at the usage of faker