Laravel 5.2 tinker has an error generating test data.
巴扎黑
巴扎黑 2017-05-16 16:51:31
0
1
354

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,
    ];
});
巴扎黑
巴扎黑

reply all(1)
刘奇

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!