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


PHP DB::commit方法代码示例

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


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

示例1: saveTrackerEntry

 public function saveTrackerEntry(Request $request)
 {
     // return $request->all();
     $validator = Validator::make($request->all(), ['desc' => 'required|min:5', 'time' => 'required|numeric', 'tags' => 'required', 'project_id' => 'required']);
     if ($request->input('project_id') == 'Select Project') {
         Session::flash('flash_error', 'You need to select the project');
         return redirect()->back()->withInput();
     }
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     try {
         DB::beginTransaction();
         $project = Project::with('client')->find($request->input('project_id'));
         $entry = TimeEntry::create(['desc' => $request->input('desc'), 'user_id' => Auth::user()->id, 'project_id' => $project->id, 'project_name' => $project->name, 'client_name' => $project->client->name, 'time' => $request->input('time')]);
         // adding the entry of the ticket with tags mapping table
         foreach ($request->input('tags') as $key => $value) {
             DB::table('taggables')->insert(['tag_id' => $value, 'taggable_id' => $entry->id, 'taggable_type' => 'ticket', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
         }
         if ($request->input('estimate_id')) {
             DB::table('time_entry_estimates')->insert(['time_entry_id' => $entry->id, 'estimate_id' => $request->input('estimate_id'), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
             DB::update("UPDATE estimates SET hours_consumed = hours_consumed + :hours WHERE id = :id", ['hours' => $request->input('time'), 'id' => $request->input('estimate_id')]);
         }
         DB::commit();
         Session::flash('flash_message', 'Entry saved');
         return redirect('time-tracker');
     } catch (\PDOException $e) {
         DB::rollBack();
         abort(403, 'Data was not saved. Try again' . $e->getMessage());
     }
 }
开发者ID:amitavroy,项目名称:Tranvas,代码行数:31,代码来源:TrackerController.php

示例2: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info("Clearing permissions... \n");
     // Delete old data
     $response = Action::deleteAllData();
     null !== $response ? $this->error("\n" . $response . "\n") : null;
     $this->info("Permissions cleared... \n");
     try {
         $routeData = $this->getRouteData();
         $roles = Role::all();
         DB::beginTransaction();
         foreach ($routeData as $action => $uri) {
             $action = new Action(['uri' => $uri, 'action' => $action]);
             $action->save();
             $this->savePermissions($roles, $action);
             $this->comment("Added action " . $action->action . "\n");
         }
         $cache = $this->getCacheInstance(['permissions']);
         $cache->flush();
         DB::commit();
     } catch (\Exception $e) {
         DB::rollBack();
         $this->error("\n" . $e->getMessage() . "\n");
     }
 }
开发者ID:Denniskevin,项目名称:Laravel5Starter,代码行数:30,代码来源:AclClear.php

示例3: testTransaction

 public function testTransaction()
 {
     DB::beginTransaction();
     DB::insert('insert into users (name,email,password) values (?,?,?)', ['ceshi', '728686686@qq.com', 'ddddd']);
     //        DB::rollback();
     DB::commit();
 }
开发者ID:jew977,项目名称:laravel5.1,代码行数:7,代码来源:TestController.php

示例4: interest

 public function interest()
 {
     DB::beginTransaction();
     Interest::create(['res' => Input::get('id'), 'wanderer' => Session::get(MateMiddleware::$VERIFY)]);
     DB::commit();
     return 'recorded';
 }
开发者ID:panboxiaosa,项目名称:passer,代码行数:7,代码来源:TradeController.php

示例5: handle

 /**
  * Handle the event.
  *
  * @param CurrencyMessageReceivedEvent
  * @return void
  */
 public function handle(CurrencyMessageReceivedEvent $event)
 {
     $timePlaced = new \DateTime($event->message->time_placed);
     $rate = MonthlyRate::where('year', $timePlaced->format('Y'))->where('month', $timePlaced->format('m'))->where('currency_from', $event->message->getAttribute('currency_from'))->where('currency_to', $event->message->getAttribute('currency_to'))->get()->first();
     if (is_null($rate)) {
         $rate = new MonthlyRate();
         $rate->tot_messages = 1;
         $rate->currency_from = $event->message->getAttribute('currency_from');
         $rate->currency_to = $event->message->getAttribute('currency_to');
         $rate->sum_rate = $event->message->getAttribute('rate');
         $rate->month = $timePlaced->format('m');
         $rate->year = $timePlaced->format('Y');
     } else {
         $rate->tot_messages++;
         $rate->sum_rate += $event->message->getAttribute('rate');
     }
     DB::beginTransaction();
     try {
         $rate->save();
         $key = $rate->currency_from . '-' . $rate->currency_to;
         $message = [$key => ['rate' => $rate->avg_rate, 'month' => $rate->month]];
         // Push message in redis to be displayed in the frontend
         $this->pushToSocket($message);
         DB::commit();
     } catch (\ErrorException $e) {
         DB::rollBack();
         // Throw the exception again to signal an error
         // in the processing
         throw $e;
     } catch (\Exception $e) {
         DB::rollBack();
         throw $e;
     }
 }
开发者ID:staribelli,项目名称:market-trade-processor,代码行数:40,代码来源:CurrencyMessageReceived.php

示例6: create

 /**
  * Creates an activity
  *
  * @param null|array $data
  * @return null|ActivityModel
  */
 public function create($data = null)
 {
     DB::beginTransaction();
     try {
         if (is_null($data)) {
             throw new NullDataException('The data array is required!');
         }
         foreach ($data as $k => $v) {
             if (!in_array($k, $this->fields)) {
                 throw new CreateActivityException('Please add the correct fields!');
             }
         }
         if (count(array_keys($data)) != count($this->fields)) {
             throw new CreateActivityException('The number of given data is different than required!');
         }
         $this->checkFields($data);
         $activity = ActivityModel::create($data);
         DB::commit();
         return $activity;
     } catch (NullDataException $e) {
         DB::rollBack();
         return $e;
     } catch (CreateActivityException $e) {
         DB::rollBack();
         return $e;
     }
 }
开发者ID:thanosalexander,项目名称:activities,代码行数:33,代码来源:Activity.php

示例7: postRegister

 /**
  * Handle a registration request for the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postRegister(Request $request)
 {
     if (!$request->ajax()) {
         return JsonHelper::invalidRequest();
     }
     $flag = ForbiddenUsername::getInstance()->checkName($request->request->get('username'));
     if ($flag) {
         return JsonHelper::json('', '用户名非法!', 40002);
     }
     $validator = $this->registrar->validator($request->all());
     if ($validator->fails()) {
         return JsonHelper::json('', $validator->messages(), 50001);
     }
     try {
         $this->auth->login($this->registrar->create($request->all()));
         DB::commit();
         return JsonHelper::json('', 'register success', 10000);
     } catch (DevBaseException $e) {
         DB::rollback();
         if (config('app.debug')) {
             var_export($e->getMessage());
             exit;
         }
         return JsonHelper::InternalDbFail();
     }
 }
开发者ID:straysh,项目名称:straysh.info,代码行数:32,代码来源:AuthController.php

示例8: run

 public function run()
 {
     if (file_exists(__DIR__ . '/cities.txt') && file_exists(__DIR__ . '/cidr_optim.txt')) {
         DB::table('ipgeobase_cities')->delete();
         $file = file(__DIR__ . '/cities.txt');
         $pattern = '#(\\d+)\\s+(.*?)\\t+(.*?)\\t+(.*?)\\t+(.*?)\\s+(.*)#';
         DB::beginTransaction();
         foreach ($file as $row) {
             if (preg_match($pattern, $row, $out)) {
                 DB::table('ipgeobase_cities')->insert(array('id' => $out[1], 'city' => $out[2], 'region' => $out[3], 'district' => $out[4], 'lat' => $out[5], 'lng' => $out[6], 'country' => ''));
             }
         }
         DB::commit();
         DB::table('ipgeobase_base')->delete();
         $file = file(__DIR__ . '/cidr_optim.txt');
         $pattern = '#(\\d+)\\s+(\\d+)\\s+(\\d+\\.\\d+\\.\\d+\\.\\d+)\\s+-\\s+(\\d+\\.\\d+\\.\\d+\\.\\d+)\\s+(\\w+)\\s+(\\d+|-)#';
         DB::beginTransaction();
         foreach ($file as $row) {
             if (preg_match($pattern, $row, $out)) {
                 DB::table('ipgeobase_base')->insert(array('long_ip1' => $out[1], 'long_ip2' => $out[2], 'ip1' => $out[3], 'ip2' => $out[4], 'country' => $out[5], 'city_id' => is_numeric($out[6]) && 0 < (int) $out[6] ? (int) $out[6] : null));
             }
         }
         DB::commit();
         $cities = DB::table('ipgeobase_cities')->join('ipgeobase_base', 'ipgeobase_cities.id', '=', 'ipgeobase_base.city_id')->select('ipgeobase_cities.id', 'ipgeobase_base.country')->get();
         DB::beginTransaction();
         foreach ($cities as $city) {
             DB::table('ipgeobase_cities')->where('id', $city->id)->update(array('country' => $city->country));
         }
         DB::commit();
     }
 }
开发者ID:vantoozz,项目名称:ipgeobase,代码行数:31,代码来源:IpgeobaseSeeder.php

示例9: doProcessing

 /**
  * Performs the actual processing
  */
 protected function doProcessing()
 {
     $this->prepareProcessContext();
     // initialization process pipeline
     $initSteps = $this->initProcessSteps();
     if (!empty($initSteps)) {
         $this->context = app(Pipeline::class)->send($this->context)->through($initSteps)->then(function (ProcessContextInterface $context) {
             return $context;
         });
         $this->afterInitSteps();
     }
     // main pipeline (actual processing)
     $steps = $this->processSteps();
     if ($this->databaseTransaction) {
         DB::beginTransaction();
     }
     try {
         $this->context = app(Pipeline::class)->send($this->context)->through($steps)->then(function (ProcessContextInterface $context) {
             if ($this->databaseTransaction) {
                 DB::commit();
             }
             return $context;
         });
     } catch (Exception $e) {
         if ($this->databaseTransaction) {
             DB::rollBack();
         }
         $this->onExceptionInPipeline($e);
         throw $e;
     }
     $this->afterPipeline();
     $this->populateResult();
 }
开发者ID:czim,项目名称:laravel-processor,代码行数:36,代码来源:PipelineProcessor.php

示例10: createResourceCallable

 /**
  * @return callable
  */
 protected function createResourceCallable()
 {
     $createOrderResource = function (Model $model, array $data) {
         if (!empty($data['relationships']['order']['data'])) {
             $orderData = $data['relationships']['order']['data'];
             if (!empty($orderData['type'])) {
                 $orderData = [$orderData];
             }
             foreach ($orderData as $order) {
                 $attributes = array_merge($order['attributes'], ['employee_id' => $model->getKey()]);
                 Orders::create($attributes);
             }
         }
     };
     return function (array $data, array $values, ErrorBag $errorBag) use($createOrderResource) {
         $attributes = [];
         foreach ($values as $name => $value) {
             $attributes[$name] = $value;
         }
         if (!empty($data['id'])) {
             $attributes[$this->getDataModel()->getKeyName()] = $values['id'];
         }
         DB::beginTransaction();
         try {
             $model = $this->getDataModel()->create($attributes);
             $createOrderResource($model, $data);
             DB::commit();
             return $model;
         } catch (\Exception $e) {
             DB::rollback();
             $errorBag[] = new Error('creation_error', 'Resource could not be created');
             throw new \Exception();
         }
     };
 }
开发者ID:marcogrueter,项目名称:laravel5-jsonapi-transformer,代码行数:38,代码来源:EmployeesController.php

示例11: create

 public function create(array $data)
 {
     DB::beginTransaction;
     //        $this->db::
     try {
         $data['status'] = 0;
         if (isset($data['cupom_code'])) {
             $cupom = $this->cupomRepository->findByField('code', $data['cupom_code'])->first();
             $data['cupom_id'] = $cupom->id;
             $cupom->used = 1;
             $cupom->save();
             unset($data['cupom_code']);
         }
         $items = $data['items'];
         unset($data['items']);
         $order = $this->repository->create($data);
         $total = 0;
         foreach ($items as $item) {
             $item['price'] = $this->productRepository->find($item['product_id'])->price;
             $order->items()->create($item);
             $total += $item['price'] * $item['qtd'];
         }
         $order->total = $total;
         if (isset($cupom)) {
             $order->total = $total - $cupom->value;
         }
         $order->save();
         DB::commit();
     } catch (\Exception $e) {
         DB::rollback();
         throw $e;
     }
 }
开发者ID:brunowerneck,项目名称:CodeDelivery,代码行数:33,代码来源:OrderService.php

示例12: placeOrder

 function placeOrder($request)
 {
     //@TODO: transaction starts
     //        DB::beginTransaction();
     \Illuminate\Support\Facades\DB::beginTransaction();
     try {
         $order = $this->create($request);
         $orderHasItemsDao = new OrderHasItemsDao();
         $eoahDao = new OrderAddressHistoryDao();
         $eoahDao->create(array('order_id' => $order->id, 'address_id' => $request['address_id']));
         $orderOrderHistoryObj = new OrderHistoryDao();
         foreach ($request['items'] as $value) {
             $orderHasItemsObj = $orderHasItemsDao->create(array('item_id' => $value['_id'], 'order_id' => $order->id, 'quantity' => $value['_quantity']));
             //$orderOrderHistoryObj->addToOrderHistory(array("item_id"=>$value['_id'],'order_id' => $order->id));
         }
         \Illuminate\Support\Facades\DB::commit();
         return $order;
     } catch (\Exception $e) {
         \Illuminate\Support\Facades\DB::rollback();
         //            throw
         print_r($e->getMessage());
         throw new \Exception("Error internal server error", 500);
     }
     // transsaction ends
     //\Illuminate\Support\Facades\Event::fire(new OrderWasMade());
 }
开发者ID:thabung,项目名称:serveaseme,代码行数:26,代码来源:OrdersDao.php

示例13: postStore

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postStore(Request $request)
 {
     $input = $request->all();
     //		return ($input['Administrative']);
     DB::beginTransaction();
     $apps = Application::create($input['REGISTRANT']);
     $input['Administrative']['registrant_id'] = $apps->id;
     $input['Technical']['registrant_id'] = $apps->id;
     if ($request->hasFile("image1")) {
         $destinationPath = 'uploads/a/';
         $fileName = time() . "-" . $request->file('image1')->getClientOriginalName();
         $request->file('image1')->move($destinationPath, $fileName);
         $input['Administrative']['image'] = $fileName;
     }
     if ($request->hasFile('image2')) {
         $destinationPath = 'uploads/t/';
         $fileName = time() . "-" . $request->file('image2')->getClientOriginalName();
         $request->file('image2')->move($destinationPath, $fileName);
         $input['Technical']['image'] = $fileName;
     }
     return 1;
     Administrative::create($input['Administrative']);
     Technical::create($input['Technical']);
     DB::commit();
     return redirect()->back()->withSuccess('Application Submitted Successfully');
 }
开发者ID:bappa2du,项目名称:laravel_admin_lte,代码行数:31,代码来源:WebController.php

示例14: reschedule

 /**
  * Reschedule an existing event.
  *
  * @param  Event  $oldEvent
  * @param  array  $data
  * @return Event
  * @throws Exception
  */
 public function reschedule(Event $oldEvent, array $data)
 {
     try {
         DB::beginTransaction();
         // Recreate venue
         $newVenue = $oldEvent->venue->replicate();
         if (is_array($data['venue']) && count($data['venue'])) {
             $newVenue->fill($data['venue']);
         }
         $newVenue->save();
         // Recreate event
         $newEvent = $oldEvent->replicate();
         if (is_array($data['event']) && count($data['event'])) {
             $newEvent->fill($data['event']);
         }
         $newEvent->status_id = EventStatus::ACTIVE;
         $newEvent->venue_id = $newVenue->id;
         $newEvent->save();
         DB::commit();
         return $newEvent;
     } catch (\Exception $e) {
         DB::rollBack();
         throw $e;
     }
 }
开发者ID:slicvic,项目名称:wgg,代码行数:33,代码来源:EventRepository.php

示例15: create

 /**
  * Creates a type
  *
  * @param null|array $data
  * @return null|TypeModel
  */
 public function create($data = null)
 {
     DB::beginTransaction();
     try {
         if (is_null($data)) {
             throw new NullDataException('The data array is required!');
         }
         foreach ($data as $k => $v) {
             if (!in_array($k, $this->fields)) {
                 throw new CreateTypeException('Please add the correct fields!');
             }
         }
         if (count(array_keys($data)) != count($this->fields)) {
             throw new CreateTypeException('The number of given data is different than required!');
         }
         if (TypeModel::whereName($data['name'])->first()) {
             throw new CreateTypeException('The type name already exists!');
         }
         $type = TypeModel::create($data);
         DB::commit();
         return $type;
     } catch (NullDataException $e) {
         DB::rollBack();
         return $e;
     } catch (CreateTypeException $e) {
         DB::rollBack();
         return $e;
     }
 }
开发者ID:thanosalexander,项目名称:activities,代码行数:35,代码来源:Type.php


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