【发布时间】:2018-08-01 11:24:01
【问题描述】:
$categoryTitles = [
'Games',
'Running',
'Hacking',
'Walking',
];
$categoryDescriptions = [
'this is nice',
'kinda cool',
'really good',
'fine',
];
$categories = factory(App\Category::class, 4)->create([
'title' => array_pop($categoryTitles),
'description' => array_pop($categoryDescriptions),
]);
通过查看上面的代码,您可能会知道我要做什么。
我想用数组中定义的自定义项运行 4 次工厂。
但它不起作用,因为它从两个数组中获取最后一个项目并且正在处理它们 4 次。直到数组为空时才需要 next 和 next。
我不知道该怎么做。我认为代码解释了我想要做什么。
【问题讨论】:
标签: php laravel laravel-5 eloquent factory