当前位置: 首页>>代码示例>>PHP>>正文


PHP Region::firstOrCreate方法代码示例

本文整理汇总了PHP中app\models\Region::firstOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP Region::firstOrCreate方法的具体用法?PHP Region::firstOrCreate怎么用?PHP Region::firstOrCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Region的用法示例。


在下文中一共展示了Region::firstOrCreate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upload

 public static function upload($filepath)
 {
     \DB::beginTransaction();
     try {
         $reader = ReaderFactory::create(Type::XLSX);
         // for XLSX files
         $reader->open($filepath);
         $cnt = 0;
         Store::where('active', 1)->update(['active' => 0]);
         foreach ($reader->getSheetIterator() as $sheet) {
             foreach ($sheet->getRowIterator() as $row) {
                 if ($cnt > 0) {
                     // dd($row);
                     $area = Area::firstOrCreate(['area' => strtoupper($row[0])]);
                     $enrollment = Enrollment::firstOrCreate(['enrollment' => strtoupper($row[1])]);
                     $distributor = Distributor::firstOrCreate(['distributor_code' => strtoupper($row[2]), 'distributor' => strtoupper($row[3])]);
                     $client = Client::firstOrCreate(['client_code' => strtoupper($row[8]), 'client_name' => strtoupper($row[9])]);
                     $channel = Channel::firstOrCreate(['channel_code' => strtoupper($row[10]), 'channel_desc' => strtoupper($row[11])]);
                     $agency = Agency::firstOrCreate(['agency_code' => strtoupper($row[19]), 'agency_name' => strtoupper($row[20])]);
                     $region = Region::firstOrCreate(['region_code' => strtoupper($row[16]), 'region' => strtoupper($row[15]), 'region_short' => strtoupper($row[14])]);
                     $customer = Customer::firstOrCreate(['customer_code' => strtoupper($row[12]), 'customer_name' => strtoupper($row[13])]);
                     $user = User::where('username', strtoupper($row[22]))->first();
                     if (empty($user) && !empty($row[22])) {
                         // dd($row);
                         $user = User::firstOrCreate(['username' => strtoupper($row[22]), 'name' => strtoupper($row[22]), 'email' => strtoupper($row[22]) . '@pcount.com', 'password' => \Hash::make($row[22])]);
                         $user->roles()->attach(2);
                     }
                     $storeExist = Store::where('store_code', strtoupper($row[5]))->first();
                     if (empty($storeExist) && !empty($row[22])) {
                         $store = Store::create(['storeid' => strtoupper($row[4]), 'store_code' => strtoupper($row[5]), 'store_code_psup' => strtoupper($row[6]), 'store_name' => strtoupper($row[7]), 'area_id' => $area->id, 'enrollment_id' => $enrollment->id, 'distributor_id' => $distributor->id, 'client_id' => $client->id, 'channel_id' => $channel->id, 'customer_id' => $customer->id, 'region_id' => $region->id, 'agency_id' => $agency->id, 'active' => 1]);
                         if (!empty($row[22])) {
                             StoreUser::insert(['store_id' => $store->id, 'user_id' => $user->id]);
                         }
                     } else {
                         $storeExist->storeid = strtoupper($row[4]);
                         $storeExist->store_code = strtoupper($row[5]);
                         $storeExist->store_code_psup = strtoupper($row[6]);
                         $storeExist->store_name = strtoupper($row[7]);
                         $storeExist->area_id = $area->id;
                         $storeExist->enrollment_id = $enrollment->id;
                         $storeExist->distributor_id = $distributor->id;
                         $storeExist->client_id = $client->id;
                         $storeExist->channel_id = $channel->id;
                         $storeExist->customer_id = $customer->id;
                         $storeExist->region_id = $region->id;
                         $storeExist->agency_id = $agency->id;
                         $storeExist->active = 1;
                         $storeExist->save();
                         StoreUser::where('store_id', $storeExist->id)->delete();
                         StoreUser::insert(['store_id' => $storeExist->id, 'user_id' => $user->id]);
                     }
                 }
                 $cnt++;
             }
         }
         \DB::commit();
     } catch (Exception $e) {
         dd($e);
         \DB::rollback();
     }
 }
开发者ID:renciebautista,项目名称:pcount2,代码行数:61,代码来源:Store.php

示例2: array

 $seasonName = $row["SEASONTYPENAME"];
 $seasonStart = $row["SEASONSTARTDATE"];
 $seasonEnd = $row["SEASONENDDATE"];
 $contractId = $row["ORGANISATIONSUPPLIERCONTRACTID"];
 $contractName = $row["ORGANISATIONSUPPLIERCONTRACTNAME"];
 $contractPeriodId = $row["CONTRACTDURATIONID"];
 $contractPeriodName = $row["CONTRACTDURATIONNAME"];
 $contractStart = $row["CONTRACTDURATIONSTARTDATE"];
 $contractEnd = $row["CONTRACTDURATIONENDDATE"];
 $currency = $row["CURRENCYISOCODE"];
 $buyPrice = $row["BUYPRICE"];
 $margin = $row["MARGIN"];
 $sellPrice = $row["SELLING"];
 $serviceTypeObj = Models\ServiceType::firstOrCreate(array('name' => $serviceType));
 $currencyObj = Models\Currency::firstOrCreate(array('code' => $currency));
 $regionObj = Models\Region::firstOrCreate(array('name' => $region));
 $supplierObj = $regionObj->suppliers()->firstOrCreate(array('name' => $supplierName, 'ts_id' => $supplierId));
 if ($occupancyId) {
     $occupancyObj = Models\Occupancy::firstOrCreate(array('id' => $occupancyId, 'name' => $occupancyName));
 }
 if ($mealName) {
     $mealObj = Models\Meal::firstOrCreate(array('name' => $mealName));
 }
 // Find or Create Service
 $serviceParams = array('ts_id' => $serviceId, 'name' => $serviceName, 'region_id' => $regionObj->id, 'currency_id' => $currencyObj->id, 'service_type_id' => $serviceTypeObj->id, 'supplier_id' => $supplierObj->id, 'name' => $serviceName);
 $serviceObj = Models\Service::firstOrCreate($serviceParams);
 // Find or Create Policies
 $policyParams = array('ts_id' => $policyId, 'name' => $policyName);
 Models\Policy::firstOrCreate($policyParams);
 // Find or Create Contracts
 $contractObj = $serviceObj->contracts()->firstOrCreate(array('ts_id' => $contractId, 'name' => $contractName));
开发者ID:jyothu,项目名称:Rates,代码行数:31,代码来源:run.php

示例3: run

 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     $folderpath = base_path() . '/database/seeds/seed_files/';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", str_replace('\\', '/', $value));
         $cnt = count($_dir);
         $name = $_dir[$cnt - 1];
         $latest_date = DateTime::createFromFormat('mdY', $latest);
         $now = DateTime::createFromFormat('mdY', $name);
         if ($now > $latest_date) {
             $latest = $name;
         }
     }
     echo $latest;
     $filePath = $folderpath . $latest . '/Masterfile.xlsx';
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $reader->open($filePath);
     echo 'Seeding ' . $filePath . PHP_EOL;
     // DB::table('areas')->truncate();
     // DB::table('enrollments')->truncate();
     // DB::table('distributors')->truncate();
     // DB::table('clients')->truncate();
     // DB::table('channels')->truncate();
     // DB::table('agencies')->truncate();
     // DB::table('regions')->truncate();
     // DB::table('customers')->truncate();
     // DB::table('stores')->truncate();
     // DB::table('invalid_stores')->truncate();
     // DB::table('store_users')->truncate();
     // $role = Role::find(2)->users()->delete();
     // dd($role);
     // add masterfiles
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Stores') {
             $cnt = 0;
             Store::where('active', 1)->update(['active' => 0]);
             foreach ($sheet->getRowIterator() as $row) {
                 if ($row[0] != '') {
                     if ($cnt > 0) {
                         // if(strtoupper($row[23]) == 'INACTIVE'){
                         // 	InvalidStore::invalid($row,'Inactive Store');
                         // }else{
                         $area = Area::firstOrCreate(['area' => strtoupper($row[0])]);
                         $enrollment = Enrollment::firstOrCreate(['enrollment' => strtoupper($row[1])]);
                         $distributor = Distributor::firstOrCreate(['distributor_code' => strtoupper($row[2]), 'distributor' => strtoupper($row[3])]);
                         $client = Client::firstOrCreate(['client_code' => strtoupper($row[8]), 'client_name' => strtoupper($row[9])]);
                         $channel = Channel::firstOrCreate(['channel_code' => strtoupper($row[10]), 'channel_desc' => strtoupper($row[11])]);
                         $agency = Agency::firstOrCreate(['agency_code' => strtoupper($row[19]), 'agency_name' => strtoupper($row[20])]);
                         $region = Region::firstOrCreate(['region_code' => strtoupper($row[16]), 'region' => strtoupper($row[15]), 'region_short' => strtoupper($row[14])]);
                         $customer = Customer::firstOrCreate(['customer_code' => strtoupper($row[12]), 'customer_name' => strtoupper($row[13])]);
                         $user = User::where('username', strtoupper($row[22]))->first();
                         if (empty($user) && !empty($row[22])) {
                             $user = User::firstOrCreate(['username' => strtoupper($row[22]), 'name' => strtoupper($row[22]), 'email' => strtoupper($row[22]) . '@pcount.com', 'password' => Hash::make($row[22])]);
                             $user->roles()->attach(2);
                         }
                         $storeExist = Store::where('store_code', strtoupper($row[5]))->first();
                         if (empty($storeExist) && !empty($row[22])) {
                             $store = Store::create(['storeid' => strtoupper($row[4]), 'store_code' => strtoupper($row[5]), 'store_code_psup' => strtoupper($row[6]), 'store_name' => strtoupper($row[7]), 'area_id' => $area->id, 'enrollment_id' => $enrollment->id, 'distributor_id' => $distributor->id, 'client_id' => $client->id, 'channel_id' => $channel->id, 'customer_id' => $customer->id, 'region_id' => $region->id, 'agency_id' => $agency->id, 'active' => 1]);
                             if (!empty($row[22])) {
                                 StoreUser::insert(['store_id' => $store->id, 'user_id' => $user->id]);
                             }
                         } else {
                             // InvalidStore::invalid($row,'Duplicate Store Code');
                             $storeExist->storeid = strtoupper($row[4]);
                             $storeExist->store_code = strtoupper($row[5]);
                             $storeExist->store_code_psup = strtoupper($row[6]);
                             $storeExist->store_name = strtoupper($row[7]);
                             $storeExist->area_id = $area->id;
                             $storeExist->enrollment_id = $enrollment->id;
                             $storeExist->distributor_id = $distributor->id;
                             $storeExist->client_id = $client->id;
                             $storeExist->channel_id = $channel->id;
                             $storeExist->customer_id = $customer->id;
                             $storeExist->region_id = $region->id;
                             $storeExist->agency_id = $agency->id;
                             $storeExist->active = 1;
                             $storeExist->save();
                             StoreUser::where('store_id', $storeExist->id)->delete();
                             StoreUser::insert(['store_id' => $storeExist->id, 'user_id' => $user->id]);
                         }
                         // }
                     }
                     $cnt++;
                 }
             }
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
开发者ID:renciebautista,项目名称:pcount2,代码行数:96,代码来源:UploadStoresTableSeeder.php


注:本文中的app\models\Region::firstOrCreate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。