search

Home  >  Q&A  >  body text

Laravel 5.2 tinker has an error generating test data.

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 model
protected $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,
    ];
});
巴扎黑巴扎黑2749 days ago369

reply all(1)I'll reply

  • 怪我咯

    怪我咯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

    reply
    0
  • Cancelreply