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


PHP Customer::firstOrCreate方法代码示例

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


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

示例1: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('customers')->truncate();
     DB::table('areas')->truncate();
     DB::table('premises')->truncate();
     DB::table('stores')->truncate();
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $filePath = 'database/seeds/seed_files/Store Mapping.xlsx';
     $reader->open($filePath);
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Sheet1') {
             $rowcnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($rowcnt > 1) {
                     if (!is_null($row[0])) {
                         $customer = Customer::firstOrCreate(['customer_code' => $row[8], 'customer' => strtoupper($row[9])]);
                         $area = Area::firstOrCreate(['area_code' => $row[2], 'area' => strtoupper($row[3])]);
                         $premise = Premise::firstOrCreate(['premise_code' => $row[4], 'premise' => strtoupper($row[5])]);
                         Store::firstOrCreate(['customer_id' => $customer->id, 'area_id' => $area->id, 'premise_id' => $premise->id, 'store_code' => strtoupper($row[0]), 'store' => strtoupper($row[1])]);
                     }
                 }
                 $rowcnt++;
             }
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
开发者ID:renciebautista,项目名称:pcount,代码行数:37,代码来源:UploadStoreMappingSeeder.php

示例2: createReservation

 public function createReservation(Request $request)
 {
     $room_info = $request['room_info'];
     $start_dt = Carbon::createFromFormat('d-m-Y', $request['start_dt'])->toDateString();
     $end_dt = Carbon::createFromFormat('d-m-Y', $request['end_dt'])->toDateString();
     $customer = Customer::firstOrCreate($request['customer']);
     $reservation = Reservation::create();
     $reservation->total_price = $room_info['total_price'];
     $reservation->occupancy = $request['occupancy'];
     $reservation->customer_id = $customer->id;
     $reservation->checkin = $start_dt;
     $reservation->checkout = $end_dt;
     $reservation->save();
     $date = $start_dt;
     while (strtotime($date) < strtotime($end_dt)) {
         $room_calendar = RoomCalendar::where('day', '=', $date)->where('room_type_id', '=', $room_info['id'])->first();
         $night = ReservationNight::create();
         $night->day = $date;
         $night->rate = $room_calendar->rate;
         $night->room_type_id = $room_info['id'];
         $night->reservation_id = $reservation->id;
         $room_calendar->availability--;
         $room_calendar->reservations++;
         $room_calendar->save();
         $night->save();
         $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
     }
     $nights = $reservation->nights;
     $customer = $reservation->customer;
     return $reservation;
 }
开发者ID:elasbandis,项目名称:ProjectBooking,代码行数:31,代码来源:ReservationController.php


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