Laravel 5.2 用tinker生成测试数据报错

QQ图片20160811205146.png

如图,菜鸟求解答;困扰了一下午了;为什么会报错!

ModelFactory.php 中代码如下:

<?php

$factory->define(App\Models\Notice::class, function (Faker\Generator $faker) {
    return [
        'title' => $faker->sentences,
        'content' => $faker->paragraph,
    ];
});

我的model是在app\\Models目录下的。

我是用 php artisan make model:Models/Notice 生成的

模型 Notice.php 之下了如下代码

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Notice extends Model
{
    protected $table = 'notice';
    protected $fillable = ['title','content'];
}

migration 如下:

<?php

Schema::create('notice', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('content');
            $table->integer('user_id')->default('0');
            $table->timestamps();
    });
tlerbao

代码本来是有格式的,发布完了还是不行。。。@JellyBool

JellyBool

恩,我正在调这个问题,貌似只有从 phpstorm 粘贴过来的代码会这样。。。

tlerbao

@JellyBool 顺便把我的问题回答一下啊老大你倒是哈哈!!!

JellyBool

没遇到过。。看报错应该是你的哪个参数传错了,应该传数组而你给了字符串

tlerbao

@JellyBool 找到问题所在了

'title' => $faker->sentences,

改成

'title' => $faker->sentence,

去掉s就行了,这个带s的是数组。靠!