Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current none :
/
var
/
www
/
html
/
tpid-aden
/
api
/
app
/
Imports
/
Or
Select Your none :
Upload File :
New :
File
Dir
/var/www/html/tpid-aden/api/app/Imports/MitraStoreImport.php
<?php namespace App\Imports; use App\Models\City; use App\Models\MitraStore; use App\Models\Mitra; use DB; use Maatwebsite\Excel\Concerns\ToModel; class MitraStoreImport implements ToModel { function __construct($location) { $this->location = $location; } /** * @param array $row * * @return \Illuminate\Database\Eloquent\Model|null */ public function model(array $row) { $mitra = Mitra::where('customer_code', $row[1])->first(); $location_code_id = ($this->location == "ADEN") ? 1 : 2; $city_name = explode(" ", $row[2]); $location_code = (!empty($mitra['id_accounting'])) ? $mitra['id_accounting'].'_'.$this->location : null; $city = City::select(['id_city', 'city_type', 'city_name'])->where('city_name', 'LIKE', '%'.$city_name[0].'%')->first(); $cities = (!empty($city)) ? $city->city_type.' '.$city->city_name : "BBA"; return new MitraStore([ "mitra_id" => $mitra['id']?? 4, "location_code_id" => $location_code_id, "store_name" => $row[2], "store_address" => $row[5] ?? null, "store_city" => $cities, "pic_address" => $row[5] ?? null, "pic_city" => $cities, "id_accounting" => $location_code, "mitra_code" => $row[1], "is_deposit" => 1, "approved_by" => 1, "pic_phone" => $row[4], "pic_name" => $row[3] ]); } }