Model Factories (5.1文档中的一个问题)

文档具体位置:
http://laravel.com/docs/master ... ories
Instead of duplicating all of the attributes from your base user factory, you may use the raw method to retrieve the base attributes. Once you have the attributes, simply supplement them with any additional values you require:
$factory->defineAs(App\User::class, 'admin', function ($faker) use ($factory) {
$user = $factory->raw(App\User::class);

return array_merge($user, ['admin' => true]);
});

$factory->raw(App\User::class);
raw方法会执行下面的代码,
$raw = call_user_func($this->definitions[$class][$name], Faker::create());
这会导致一个循环调用;
因为$this->definitions[$class][$name]上绑定的正是$factory所定义的那个Closure.
已邀请:

要回复问题请先登录注册