本文整理汇总了PHP中app\models\Customer::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::firstOrNew方法的具体用法?PHP Customer::firstOrNew怎么用?PHP Customer::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Customer
的用法示例。
在下文中一共展示了Customer::firstOrNew方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
public function import()
{
try {
$file = Input::file('file');
//$path = Input::file('pricelist')->getRealPath();
$temp = null;
Excel::load($file, function ($reader) use($temp) {
//$reader->dump();
$reader->skip(1);
// Loop through all rows
$reader->each(function ($row) {
$carBrand = CarBrand::where('name', 'NISSAN')->first();
$color = Color::where('code', trim($row->p))->first();
$carModel = CarModel::firstOrCreate(['name' => trim($row->c) . ' ' . trim($row->d), 'cartypeid' => $row->b, 'carbrandid' => $carBrand->id]);
$carSubModel = CarSubModel::firstOrCreate(['code' => trim($row->f), 'name' => trim($row->e), 'carmodelid' => $carModel->id]);
$car = Car::firstOrNew(['engineno' => trim($row->m), 'chassisno' => trim($row->n)]);
$car->datatype = 0;
$car->provinceid = trim($row->a);
$car->carmodelid = $carModel->id;
$car->carsubmodelid = $carSubModel->id;
$car->receivetype = trim($row->g);
$car->dealername = trim($row->h);
$car->no = trim($row->i);
$car->dodate = trim($row->j);
$car->dono = trim($row->k);
if ($row->l != null && $row->l != '') {
$car->receiveddate = trim($row->l);
}
if ($row->o != null && $row->o != '') {
$car->keyno = trim($row->o);
}
$car->colorid = $color->id;
$car->objective = trim($row->q);
if ($row->r != null && $row->r != '') {
$car->parklocation = trim($row->r);
}
if ($row->s != null && $row->s != '') {
$car->notifysolddate = trim($row->s);
}
if ($row->u != null && $row->u != '' && $row->v != null && $row->v != '') {
$customer = Customer::firstOrNew(['provinceid' => trim($row->a), 'title' => trim($row->u), 'firstname' => trim($row->v), 'lastname' => trim($row->w)]);
$customer->isreal = true;
if ($row->x != null && $row->x != '') {
$customer->phone1 = trim($row->x);
}
if ($row->y != null && $row->y != '') {
$customer->occupationid = trim($row->y);
}
if ($row->z != null && $row->z != '') {
$customer->birthdate = trim($row->z);
}
if ($row->aa != null && $row->aa != '') {
$customer->address = trim($row->aa);
}
$district = District::where('name', trim($row->ab))->first();
$amphur = Amphur::where('name', trim($row->ac))->first();
$province = Province::where('name', trim($row->ad))->first();
if ($district != null) {
$customer->districtid = $district->id;
}
if ($amphur != null) {
$customer->amphurid = $amphur->id;
}
if ($province != null) {
$customer->addprovinceid = $province->id;
}
if ($row->ad != null && $row->ad != '') {
$customer->zipcode = trim($row->ae);
}
$customer->save();
$car->issold = true;
$car->buyercustomerid = $customer->id;
if ($row->t != null && $row->t != '') {
$car->isdelivered = true;
}
}
$car->save();
});
});
} catch (Exception $e) {
return 'Message: ' . $e->getMessage();
}
return redirect()->action('CarController@index');
}