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

1

2

3

4

5

6

7

8

9

10

<code>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();

        });

    }</code>

Then my model is

1

<code>php artisan make:model Models/Notice</code>

Models/Notice.php only writes

in the model

1

2

<code>protected $table = 'notice';

protected $fillable = ['title','content'];</code>

ModelFactory.php is like this

1

2

3

4

5

6

<code>$factory->define(App\Models\Notice::class, function (Faker\Generator $faker) {

    return [

        'title' => $faker->sentences,

        'content' => $faker->paragraph,

    ];

});</code>

巴扎黑巴扎黑2904 days ago457

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-16 16:53:31

    It should be something wrong in Modelfactory.php.

    1

    2

    3

    4

    <code>'title' => $faker->sentences,

    改为

    'title' => $faker->sentence,

    </code>

    $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