我想更新2个关系表,我已经尝试过,但是遇到错误。我正在使用laravel 5.7和Maatwebsite 3.1。
这是我的控制器,我将excel数据放在$ data中:
public function import(){
$data = Excel::toArray(new AssignmentFAImport, request()->file('file'));
if ($data) {
collect(head($data))
->each(function ($row, $key) {
DB::table('fa_transaction')
->join('customer', 'fa_transaction.fa_transaction_id', '=', 'customer.fa_transaction_id')
->where('fa_transaction_id', $row['fa_transaction_id'])
->update(array_except($row, ['fa_transaction_id']));
});
return "Success";
}else{
return "Can not update";
}
}
和此导入类:
<?php
namespace App\Imports;
use App\Models\Transaction\FA_transaction;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class AssignmentFAImport implements ToModel, WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new FA_transaction([
'nomen' => $row['nomen'],
'dispatch_group' => $row['dispatch_group'],
'address' => $row['address'],
'fa_transaction_id' => $row['fa_transaction_id'],
'fa_type_cd' => $row['fa_type_cd'],
'pcezbk' => $row['pcezbk'],
'status' => $row['status'],
'created_at' => $row['created_at'],
'worker_id' => $row['worker_id'],
'assign_date' => $row['assign_status'],
'reassigned_date' => $row['reassigned_date'],
'assign_status' => $row['assign_status'],
'urgent_status' => $row['urgent_status'],
'priority_status' => $row['priority_status'],
'sending_status' => $row['sending_status']
]);
}
}
我收到这样的错误:
Illuminate \ Database \ QueryException(42000)SQLSTATE [42000]: [Microsoft] [用于SQL Server的ODBC驱动程序11] [SQL Server]模棱两可 列名“ fa_transaction_id”。 (SQL:更新[fa_transaction]集 [nomen] = 60215072,[dispatch_group] = CC31-DR,[address] = JL KALI BARU TMR NO 32 RT 012 RW 013,[fa_type_cd] = FA-T4E,[pcezbk] = 0760309,[状态] = P,[创建的日期] = 2018-11-16 00:00:00.000, [worker_id] = 2,[assign_date] = 2019-01-22 08:54:48.000, [reassigned_date] =,[assign_status] =已分配,[urgent_status] = 1,[priority_status] =,[sending_status] =来自[fa_transaction]上的[fa_transaction]内部联接[客户]。[fa_transaction_id] = [客户]。[fa_transaction_id] 其中[fa_transaction_id] = 0210559377)
我不知道列名为什么不明确,如何解决?