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


PHP DB::beginTransaction方法代码示例

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


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

示例1: 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

示例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: 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

示例4: 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

示例5: 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

示例6: update

 public function update(Request $request, $id)
 {
     $departamento = $request->input('departamento');
     if ($departamento != '0') {
         try {
             DB::beginTransaction();
             $usuario = User::find($id);
             $empleado = $usuario->empleado;
             $empleado->nombre = Str::upper($request->input('nombre'));
             $empleado->apellido_paterno = Str::upper($request->input('apellido_paterno'));
             $empleado->apellido_materno = Str::upper($request->input('apellido_materno'));
             $empleado->save();
             $usuario->username = Str::upper($request->input('username'));
             $usuario->password = bcrypt($request->input('password'));
             $usuario->rol_id = $request->input('departamento');
             $usuario->save();
             DB::commit();
             return redirect()->route('usuario.index');
         } catch (QueryException $e) {
             echo $e;
             DB::rollBack();
             return redirect()->route('usuario.edit', $id);
         }
     } else {
         return redirect()->route('usuario.edit', $id);
     }
 }
开发者ID:Chupolandia,项目名称:Syscofovet,代码行数:27,代码来源:UsuarioController.php

示例7: 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

示例8: 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

示例9: veritranscc

 /**
  * Veritrans Credit Card
  *
  * 1. Check Order
  * 2. Save Payment
  * 
  * @return Response
  */
 public function veritranscc()
 {
     if (!Input::has('order_id')) {
         return new JSend('error', (array) Input::all(), 'Tidak ada data order id.');
     }
     $errors = new MessageBag();
     DB::beginTransaction();
     //1. Validate Sale Parameter
     $order = Input::only('order_id', 'gross_amount', 'payment_type', 'masked_card', 'transaction_id');
     //1a. Get original data
     $sale_data = \App\Models\Sale::findorfail($order['order_id']);
     //2. Save Payment
     $paid_data = new \App\Models\Payment();
     $payment['transaction_id'] = $sale_data['id'];
     $payment['method'] = $order['payment_type'];
     $payment['destination'] = 'Veritrans';
     $payment['account_name'] = $order['masked_card'];
     $payment['account_number'] = $order['transaction_id'];
     $payment['ondate'] = \Carbon\Carbon::parse($order['transaction_time'])->format('Y-m-d H:i:s');
     $payment['amount'] = $order['gross_amount'];
     $paid_data = $paid_data->fill($payment);
     if (!$paid_data->save()) {
         $errors->add('Log', $paid_data->getError());
     }
     if ($errors->count()) {
         DB::rollback();
         return response()->json(new JSend('error', (array) Input::all(), $errors), 404);
     }
     DB::commit();
     $final_sale = \App\Models\Sale::id($sale_data['id'])->with(['voucher', 'transactionlogs', 'user', 'transactiondetails', 'transactiondetails.varian', 'transactiondetails.varian.product', 'paidpointlogs', 'payment', 'shipment', 'shipment.address', 'shipment.courier', 'transactionextensions', 'transactionextensions.productextension'])->first()->toArray();
     return response()->json(new JSend('success', (array) $final_sale), 200);
 }
开发者ID:ThunderID,项目名称:SHOP-API,代码行数:40,代码来源:PaymentController.php

示例10: 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

示例11: setPassword

 /**
  * set pasword
  *
  * 1. get activation link
  * 2. validate activation
  * @param activation link
  * @return array of employee
  */
 public function setPassword($activation_link)
 {
     if (!Input::has('activation')) {
         return new JSend('error', (array) Input::all(), 'Tidak ada data activation.');
     }
     $errors = new MessageBag();
     DB::beginTransaction();
     //1. Validate activation Parameter
     $activation = Input::get('activation');
     //1. get activation link
     $employee = Employee::activationlink($activation_link)->first();
     if (!$employee) {
         $errors->add('Activation', 'Invalid activation link');
     }
     //2. validate activation
     $rules = ['password' => 'required|min:8|confirmed'];
     $validator = Validator::make($activation, $rules);
     if ($validator->passes()) {
         $employee->password = $activation['password'];
         $employee->activation_link = '';
         if (!$employee->save()) {
             $errors->add('Activation', $employee->getError());
         }
     } else {
         $errors->add('Activation', $validator->errors());
     }
     if ($errors->count()) {
         DB::rollback();
         return new JSend('error', (array) Input::all(), $errors);
     }
     DB::commit();
     return new JSend('success', ['employee' => $employee->toArray()]);
 }
开发者ID:ThunderID,项目名称:HRIS-API,代码行数:41,代码来源:EmploymentAccountController.php

示例12: postAddIntrare

 public function postAddIntrare()
 {
     $rules = array('expeditor' => 'required', 'destinatar' => 'required');
     $errors = array('required' => 'Campul este obligatoriu.');
     $validator = Validator::make(Input::all(), $rules, $errors);
     if ($validator->fails()) {
         return Redirect::back()->with('message', 'Eroare validare formular!')->withErrors($validator)->withInput();
     } else {
         DB::beginTransaction();
         try {
             $numar_inregistrare = DB::table('registru_intrare')->select(DB::raw('max(numar_inregistrare) AS numar_inregistrare'))->where('logical_delete', 0)->get();
             $urmatorul_numar_inregistrare = 0;
             if ($numar_inregistrare[0]->numar_inregistrare > 0) {
                 $urmatorul_numar_inregistrare = $numar_inregistrare[0]->numar_inregistrare;
             }
             $urmatorul_numar_inregistrare++;
             DB::table('registru_intrare')->insertGetId(array('numar_inregistrare' => $urmatorul_numar_inregistrare, 'expeditor' => Input::get('expeditor'), 'numar_inregistrare_expeditor' => Input::get('numar_inregistrare_expeditor'), 'numar_anexe' => Input::get('numar_anexe'), 'continut' => Input::get('continut'), 'destinatar' => Input::get('destinatar'), 'observatii' => Input::get('observatii')));
         } catch (Exception $e) {
             DB::rollback();
             return Redirect::back()->with('message', 'Eroare salvare date: ' . $e)->withInput();
         }
         DB::commit();
         return Redirect::back()->with('message', 'Salvare realizata cu succes!');
     }
 }
开发者ID:binaryk,项目名称:lareab,代码行数:25,代码来源:RegistruIntrareController.php

示例13: 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

示例14: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::beginTransaction();
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     DB::table('routes')->delete();
     DB::table('contents')->delete();
     DB::table('categories')->delete();
     DB::table('content_types')->delete();
     DB::table('languages')->delete();
     DB::table('group_user')->delete();
     DB::table('user_meta')->delete();
     DB::table('users')->delete();
     DB::table('groups')->delete();
     DB::table('routes')->truncate();
     DB::table('contents')->truncate();
     DB::table('categories')->truncate();
     DB::table('content_types')->truncate();
     DB::table('languages')->truncate();
     DB::table('group_user')->truncate();
     DB::table('user_meta')->truncate();
     DB::table('users')->truncate();
     DB::table('groups')->truncate();
     DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     DB::commit();
     Model::reguard();
 }
开发者ID:philsown,项目名称:seia-laravel-core,代码行数:32,代码来源:DatabaseCleaner.php

示例15: 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


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