Laravel:从 url 播种数据库时出错
Laravel: error while seeding database from an url
我正在尝试为我的数据库设置种子 table。我收到以下错误。
public function run()
{
//
$json = file_get_contents('http://www.ottawacityjobs.ca/en/data/');
$emplois = json_decode($json);
foreach ($emplois as $item) {
Emploi::insert(
array(
array('JOBURL' => $item->JOBURL ),
array('SALARYMAX' => $item->SALARYMAX ),
array('SALARYMIN' => $item->SALARYMIN ),
array('SALARYTYPE' => $item->SALARYTYPE ),
array('NAME' => $item->NAME ),
array('POSITION' => $item->POSITION ),
array('JOBREF' => $item->JOBREF ),
array('JOB_SUMMARY' => $item->JOB_SUMMARY ),
array('POSTDATE' => $item->POSTDATE ),
array('EXPIRYDATE' => $item->EXPIRYDATE ),
array('KNOWLEDGE' => $item->KNOWLEDGE ),
array('LANGUAGE_CERTIFICATES' => $item->LANGUAGE_CERTIFICATES ),
array('EDUCATIONANDEXP' => $item->EDUCATIONANDEXP ),
array('COMPANY_DESC' => $item->COMPANY_DESC ),
));
}//end foreach
您提供的 URL (http://www.ottawacityjobs.ca/en/data/
) 没有在您访问时显示数据。 json 的结构如下:
{
jobs: [
{...},
{...},
{...}
]
}
因此您的代码需要遍历 jobs
属性:
public function run()
{
//
$json = file_get_contents('http://www.ottawacityjobs.ca/en/data/');
$emplois = json_decode($json);
foreach ($emplois->jobs as $item) {
Emploi::insert(
array(
array('JOBURL' => $item->JOBURL ),
array('SALARYMAX' => $item->SALARYMAX ),
array('SALARYMIN' => $item->SALARYMIN ),
array('SALARYTYPE' => $item->SALARYTYPE ),
array('NAME' => $item->NAME ),
array('POSITION' => $item->POSITION ),
array('JOBREF' => $item->JOBREF ),
array('JOB_SUMMARY' => $item->JOB_SUMMARY ),
array('POSTDATE' => $item->POSTDATE ),
array('EXPIRYDATE' => $item->EXPIRYDATE ),
array('KNOWLEDGE' => $item->KNOWLEDGE ),
array('LANGUAGE_CERTIFICATES' => $item->LANGUAGE_CERTIFICATES ),
array('EDUCATIONANDEXP' => $item->EDUCATIONANDEXP ),
array('COMPANY_DESC' => $item->COMPANY_DESC ),
));
}//end foreach
我正在尝试为我的数据库设置种子 table。我收到以下错误。
public function run()
{
//
$json = file_get_contents('http://www.ottawacityjobs.ca/en/data/');
$emplois = json_decode($json);
foreach ($emplois as $item) {
Emploi::insert(
array(
array('JOBURL' => $item->JOBURL ),
array('SALARYMAX' => $item->SALARYMAX ),
array('SALARYMIN' => $item->SALARYMIN ),
array('SALARYTYPE' => $item->SALARYTYPE ),
array('NAME' => $item->NAME ),
array('POSITION' => $item->POSITION ),
array('JOBREF' => $item->JOBREF ),
array('JOB_SUMMARY' => $item->JOB_SUMMARY ),
array('POSTDATE' => $item->POSTDATE ),
array('EXPIRYDATE' => $item->EXPIRYDATE ),
array('KNOWLEDGE' => $item->KNOWLEDGE ),
array('LANGUAGE_CERTIFICATES' => $item->LANGUAGE_CERTIFICATES ),
array('EDUCATIONANDEXP' => $item->EDUCATIONANDEXP ),
array('COMPANY_DESC' => $item->COMPANY_DESC ),
));
}//end foreach
您提供的 URL (http://www.ottawacityjobs.ca/en/data/
) 没有在您访问时显示数据。 json 的结构如下:
{
jobs: [
{...},
{...},
{...}
]
}
因此您的代码需要遍历 jobs
属性:
public function run()
{
//
$json = file_get_contents('http://www.ottawacityjobs.ca/en/data/');
$emplois = json_decode($json);
foreach ($emplois->jobs as $item) {
Emploi::insert(
array(
array('JOBURL' => $item->JOBURL ),
array('SALARYMAX' => $item->SALARYMAX ),
array('SALARYMIN' => $item->SALARYMIN ),
array('SALARYTYPE' => $item->SALARYTYPE ),
array('NAME' => $item->NAME ),
array('POSITION' => $item->POSITION ),
array('JOBREF' => $item->JOBREF ),
array('JOB_SUMMARY' => $item->JOB_SUMMARY ),
array('POSTDATE' => $item->POSTDATE ),
array('EXPIRYDATE' => $item->EXPIRYDATE ),
array('KNOWLEDGE' => $item->KNOWLEDGE ),
array('LANGUAGE_CERTIFICATES' => $item->LANGUAGE_CERTIFICATES ),
array('EDUCATIONANDEXP' => $item->EDUCATIONANDEXP ),
array('COMPANY_DESC' => $item->COMPANY_DESC ),
));
}//end foreach