我在laravel应用程序之外使用Laravel Illuminate / Database。我试图将Eloquent模型作为我的闭包参数传递但是它抛出一个错误。可能是我错误地传递了它。我的代码如下:
// Create a dummy subject (This is working absolutely fine)
SubjectModel::create(array(
'title' => 'Mathematics',
'description' => 'Math Subject',
'slug' => 'math',
'ka_url' => 'http://khanacademy.org/math'
));
$scrapper = new SubjectScrapper();
$scrapper->setUrl('');
这不起作用。 SubjectModel未在以下闭包中传递
$scrapper->runScrapper(function($subjects) use ($scrapper, SubjectModel $subjectModel) {
if(!empty($subjects))
{
foreach ($subjects as $subject) {
$urlParts = explode('/', $subject['url']);
$slug = end($urlParts);
$subjectModel::create(array(
'title' => $subject['subject_name'],
'slug' => $slug,
'ka_url' => $scrapper->getBaseUrl().$subject['link'],
));
}
}
});
请有人告诉我如何完成这项任务。
答案 0 :(得分:1)
试试这个。无需在闭包中传递对象
EnumType