Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel中唯一ID行的插入问题_Php_Database_Postgresql_Csv_Laravel 5 - Fatal编程技术网

Php laravel中唯一ID行的插入问题

Php laravel中唯一ID行的插入问题,php,database,postgresql,csv,laravel-5,Php,Database,Postgresql,Csv,Laravel 5,我正在尝试将一些csv数据插入名为tuhanorder的表中。我只想插入那些其orderbango之前未插入的行。这是我的密码 $orderhenkan=tuhanorder::firstOrCreate(['orderbango' => $orderbango], ['juchukubun2'=> 'ヤマト運輸'], ['soufusakibango'=> $syukkosak

我正在尝试将一些csv数据插入名为
tuhanorder
的表中。我只想插入那些其
orderbango
之前未插入的行。这是我的密码

$orderhenkan=tuhanorder::firstOrCreate(['orderbango' => $orderbango],
                         ['juchukubun2'=> 'ヤマト運輸'],
                         ['soufusakibango'=> $syukkosakibango],
                         ['chumonsyabango'=>(!empty($thanerjonno))],
                         ['money2'=>(!empty($answers[$i]['int17']))],
                         ['money3'=>(!empty($answers[$i]['int18']))],
                         ['money5'=>(!empty($answers[$i]['int19']))],
                         ['money4'=>(!empty($answers[$i]['int31']))],
                         ['moneymax'=>(!empty($answers[$i]['int30']))],
                         ['otodokedate'=>(!empty($answers[$i]['int22']))],
                         ['youbou'=> $answers[$i]['int20']],
                         ['chumonsyajouhou'=> $answers[$i]['int21']],
                         ['otodoketime'=> $answers[$i]['int23']],
                         ['information4'=> $answers[$i]['int24']],
                         ['kessaihouhou'=> $answers[$i]['int25']],
                         ['juchubango'=> $answers[$i]['int0']],
                         ['chumondate'=> $answers[$i]['int1']],
                         ['information5'=>$answers[$i]['int2']],
                         ['juchukubun1'=> $answers[$i]['int10']]);
$tuhanorder=tuhanorder::firstOrCreate(['orderbango' => $orderbango],
                         ['juchukubun2'=> 'ヤマト運輸',
                           'soufusakibango'=> $syukkosakibango,
                           'chumonsyabango'=>(!empty($thanerjonno) ? $thanerjonno : null ),
                           'money2'=>(!empty($answers[$i]['int17']) ? $answers[$i]['int17'] : null ),
                           'money3'=>(!empty($answers[$i]['int19']) ? $answers[$i]['int19'] : null ),
                           'money5'=>(!empty($answers[$i]['int18']) ? $answers[$i]['int18'] : null ),
                           'money4'=>(!empty($answers[$i]['int31']) ? $answers[$i]['int31'] : null ),
                           'moneymax'=>(!empty($answers[$i]['int30']) ? $answers[$i]['int30'] : null ),
                           'otodokedate'=>(!empty($answers[$i]['int22']) ? $answers[$i]['int22'] : null ),
                           'youbou'=> $answers[$i]['int20'],
                           'chumonsyajouhou'=> $answers[$i]['int21'],
                           'otodoketime'=> $answers[$i]['int23'],
                           'information4'=> $answers[$i]['int24'],
                           'kessaihouhou'=> $answers[$i]['int25'],
                           'juchubango'=> $answers[$i]['int0'],
                           'chumondate'=> $answers[$i]['int1'],
                           'information5'=>$answers[$i]['int2'],
                           'juchukubun1'=> $answers[$i]['int10']
                         ]);

我的代码正在运行。但它只是插入了前两个元素。Rest在数据库中为空。我正在使用postgresql作为数据库

首先是拉威尔的质量分配概念问题。 您必须将所有表字段指定到模型的$fillable数组中(tuhanorder)

其次,我注意到您只是在检查条件,但如果条件匹配,则必须插入如下数据:

'money2'=>(!empty($answers[$i]['int17']) ? $answers[$i]['int17'] : "");

我已经解决了这个问题。这是我的密码

$orderhenkan=tuhanorder::firstOrCreate(['orderbango' => $orderbango],
                         ['juchukubun2'=> 'ヤマト運輸'],
                         ['soufusakibango'=> $syukkosakibango],
                         ['chumonsyabango'=>(!empty($thanerjonno))],
                         ['money2'=>(!empty($answers[$i]['int17']))],
                         ['money3'=>(!empty($answers[$i]['int18']))],
                         ['money5'=>(!empty($answers[$i]['int19']))],
                         ['money4'=>(!empty($answers[$i]['int31']))],
                         ['moneymax'=>(!empty($answers[$i]['int30']))],
                         ['otodokedate'=>(!empty($answers[$i]['int22']))],
                         ['youbou'=> $answers[$i]['int20']],
                         ['chumonsyajouhou'=> $answers[$i]['int21']],
                         ['otodoketime'=> $answers[$i]['int23']],
                         ['information4'=> $answers[$i]['int24']],
                         ['kessaihouhou'=> $answers[$i]['int25']],
                         ['juchubango'=> $answers[$i]['int0']],
                         ['chumondate'=> $answers[$i]['int1']],
                         ['information5'=>$answers[$i]['int2']],
                         ['juchukubun1'=> $answers[$i]['int10']]);
$tuhanorder=tuhanorder::firstOrCreate(['orderbango' => $orderbango],
                         ['juchukubun2'=> 'ヤマト運輸',
                           'soufusakibango'=> $syukkosakibango,
                           'chumonsyabango'=>(!empty($thanerjonno) ? $thanerjonno : null ),
                           'money2'=>(!empty($answers[$i]['int17']) ? $answers[$i]['int17'] : null ),
                           'money3'=>(!empty($answers[$i]['int19']) ? $answers[$i]['int19'] : null ),
                           'money5'=>(!empty($answers[$i]['int18']) ? $answers[$i]['int18'] : null ),
                           'money4'=>(!empty($answers[$i]['int31']) ? $answers[$i]['int31'] : null ),
                           'moneymax'=>(!empty($answers[$i]['int30']) ? $answers[$i]['int30'] : null ),
                           'otodokedate'=>(!empty($answers[$i]['int22']) ? $answers[$i]['int22'] : null ),
                           'youbou'=> $answers[$i]['int20'],
                           'chumonsyajouhou'=> $answers[$i]['int21'],
                           'otodoketime'=> $answers[$i]['int23'],
                           'information4'=> $answers[$i]['int24'],
                           'kessaihouhou'=> $answers[$i]['int25'],
                           'juchubango'=> $answers[$i]['int0'],
                           'chumondate'=> $answers[$i]['int1'],
                           'information5'=>$answers[$i]['int2'],
                           'juchukubun1'=> $answers[$i]['int10']
                         ]);