我正在尝试导入大量记录。记录位于 .CSV 文件中。
记录应转到“DocCertification”哪个模型。记录具有依赖于其他模型的字段。
我所做的是创建一个使用TestController
. 我收到错误:
试图获取非对象的属性“n_matriculated”
但我也明白了public function getCustomerId()
。
我不知道我做错了什么。
<?php
namespace App\Http\Controllers;
use App\DocCertification;
use App\MatProfessionalDetail;
use App\AuxCustomer;
use App\AuxItem;
use Illuminate\Http\Request;
class TestController extends Controller{
public function import(){
$path = public_path('certificaciones.csv');
$lines = file($path);
$utf8_lines = array_map ('utf8_encode', $lines);
$array = array_map(function($v){return str_getcsv($v, ";");}, $utf8_lines);
for ($i=1; $i < sizeof($array) ; $i+1){
$certification = new DocCertification();
$certification-> date = $array[$i][0];
$certification-> n_matriculated = $this->getMatriculatedId($array[$i][1]);
$certification-> customer = $this->getCustomerId($array[$i][2]);
$certification-> n_invoice = $array[$i][3];
$certification-> item = $array[$i][4];
$certification-> mod = $this->getModId($array[$i][5]);
$certification-> obs = $array[$i][6];
$certification-> save();
}
}
public function getMatriculatedId($matriculatedID)
{
$matriculated = MatProfessionalDetail::where('n_matriculated', $matriculatedID)->first();
return $matriculated->n_matriculated;
}
public function getCustomerId($customerID)
{
$customer = AuxCustomer::where('customer', $customer)->first();
if($customer){
return $customer->name;
}
$customer = new AuxCustomer();
$customer-> name = $customerID;
$customer-> cuil_cuit = 'CUIT';
$customer-> c_c_number = 0;
$customer-> dni = 0;
$customer-> save();
return $customer->name;
}
我不明白我应该做什么。
这是它显示的错误:
元芳怎么了