dongnachuang6635 2017-06-17 02:17
浏览 76
已采纳

Laravel:如何将数据库种植到db.table的多个字段中

I want to seed my database but everything is getting insert into one field (JOBURL) enter image description here

EmploisTableSeeder.php

use Illuminate\Database\Seeder;
use App\Emploi;
class EmploisTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     *
     *php artisan db:seed --class=EmploisTableSeeder
     */
    public function run()
    {
        //
        $json = file_get_contents('http://www.ottawacityjobs.ca/en/data/');
        $emplois = json_decode($json);
        $emplois = $emplois->jobs;

        //$emp = Emploi::create($array['order']);
        //$emp = Emploi::create($emplois);



        for ($i = 0; $i < count($emplois); $i++) {
            //print_r($emplois[$i]->JOBREF);
            //print_r("
");

            Emploi::insert(
                array(
array('JOBURL' => isset($emplois[$i]->JOBURL) ? $emplois[$i]->JOBURL   : ' '),
array('SALARYMAX' => isset($emplois[$i]->SALARYMAX)?  $emplois[$i]->SALARYMAX  : ' ' ),
array('SALARYMIN' => isset($emplois[$i]->SALARYMIN)?   $emplois[$i]->SALARYMIN : ' ' ),
array('SALARYTYPE' => isset($emplois[$i]->SALARYTYPE)? $emplois[$i]->SALARYTYPE : ' ' ),
array('NAME' => isset($emplois[$i]->NAME)? $emplois[$i]->NAME : ' ' ),
array('POSITION' => isset($emplois[$i]->POSITION)? $emplois[$i]->POSITION : ' ' ),
array('JOBREF' => isset($emplois[$i]->JOBREF) ? $emplois[$i]->JOBREF : ' '),
array('JOB_SUMMARY' => isset($emplois[$i]->JOB_SUMMARY) ? $emplois[$i]->JOB_SUMMARY : ' '),
array('POSTDATE' => isset($emplois[$i]->POSTDATE) ? $emplois[$i]->POSTDATE : ' '),
array('EXPIRYDATE' => isset($emplois[$i]->EXPIRYDATE)? $emplois[$i]->EXPIRYDATE : ' ' ),
array('KNOWLEDGE' => isset($emplois[$i]->KNOWLEDGE) ? $emplois[$i]->KNOWLEDGE : ' '),
array('LANGUAGE_CERTIFICATES' => isset($emplois[$i]->LANGUAGE_CERTIFICATES) ?  $emplois[$i]->LANGUAGE_CERTIFICATES : ' ' ),
array('EDUCATIONANDEXP' => isset($emplois[$i]->EDUCATIONANDEXP) ? $emplois[$i]->EDUCATIONANDEXP : ' ' ),
array('COMPANY_DESC' => isset( $emplois[$i]->COMPANY_DESC) ? $emplois[$i]->COMPANY_DESC   : ' '),

                )//end array
                );//end Emploi::insert




        }
            //print_r(dd($emplois));

    }//end run function
}// end class EmploiTableSeeder

So overall I have about 90 json objects that I loop through but everything is getting inserted into one field.

  • 写回答

1条回答 默认 最新

  • drap5081683 2017-06-17 02:23
    关注

    Include every field in single array. Do it like this.

    array(
    'JOBURL' => isset($emplois[$i]->JOBURL) ? $emplois[$i]->JOBURL   : ' ',
    'SALARYMAX' => isset($emplois[$i]->SALARYMAX)?  $emplois[$i]->SALARYMAX  : ' ',
    ),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?