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

求大神指教为什么会报错!
详细信息:
ModelFactory.php 中代码如下:
$factory->define(App\Models\Notice::class, function (Faker\Generator $faker) {
return [
'title' => $faker->sentences,
'content' => $faker->paragraph,
];
});
模型 Notice.php 之下了如下代码
我的model是在app\Models目录下的;我是用 php artisan make model:Models/Notice 生成的
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Notice extends Model
{
protected $table = 'notice';
protected $fillable = ['title','content'];
}
migration 如下:
Schema::create('notice', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('content');
$table->integer('user_id')->default('0');
$table->timestamps();
});
关于 LearnKu
问题原因
错误提示已经描述的很清楚了
即原本输入应该是字符类型,结果却输入成了数组类型。
解决方案
将
ModelFactory.php文件中的修改成
对,就是去掉了一个 's' 字符,官方文档里有解释这个 sentences 的用法:
返回的是
array类型的哦。更多的 faker 用法可以参考官方文档哦:https://github.com/fzaninotto/Faker
@monkey 牛B,知道了!!!