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


PHP DB::transaction方法代码示例

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


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

示例1: addAnswer

 public function addAnswer(Question $question, $answer)
 {
     $member = $this;
     \DB::transaction(function () use($question, $member, $answer) {
         $member->questions()->attach($question->id, ['value' => $answer]);
         $member->answer_position = $question->position;
         $member->save();
     });
     return $this;
 }
开发者ID:Sparclex,项目名称:studie,代码行数:10,代码来源:Member.php

示例2: createNew

 public function createNew()
 {
     //create transaction method
     try {
         $new = DB::transaction(function () {
             //define rules for the features.
             $feature_rules = ['name' => 'required', 'url' => 'required', 'icon' => 'required', 'module' => 'required|unique:features'];
             //get the form inputs from the POST
             $inputs = Input::all();
             //create new feature object, compare input with rules and after that create new entry into db
             $feature = new Feature();
             $feature_result = $feature->doCreate($inputs, $feature_rules);
             if ($feature_result['status'] != 1) {
                 throw new Exception($feature_result['message']);
             }
             //if CRUD is selected.
             if ($inputs['crud'] == '1') {
                 //define rules for permission
                 $permission_rules = ValidationRule::$permissionCreate;
                 // create inputs field for permission that need to be created - RestFul
                 $permission_inputs = array(['feature_id' => $feature_result['data']['id'], 'name' => 'create', 'descr' => 'Create Form', 'module' => $feature_result['data']['module'], 'position' => 'panel-default', 'url' => '/crm/' . $feature_result['data']['module'] . '/create', 'icon' => 'fa-plus', 'icon_bg' => 'btn-primary', 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'store', 'descr' => 'store record', 'module' => $feature_result['data']['module'], 'position' => 'form', 'url' => '/crm/' . $feature_result['data']['module'], 'icon' => null, 'icon_bg' => null, 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'show', 'descr' => 'Show Details', 'module' => $feature_result['data']['module'], 'position' => 'table', 'url' => '/crm/' . $feature_result['data']['module'] . '/[ID]', 'icon' => 'fa-file-text-o', 'icon_bg' => 'btn-success', 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'edit', 'descr' => 'Edit Details', 'module' => $feature_result['data']['module'], 'position' => 'table', 'url' => '/crm/' . $feature_result['data']['module'] . '/[ID]/edit', 'icon' => 'fa-edit', 'icon_bg' => 'btn-warning', 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'update', 'descr' => 'Update Details', 'module' => $feature_result['data']['module'], 'position' => 'form', 'url' => '/crm/' . $feature_result['data']['module'] . '/[ID]', 'icon' => null, 'icon_bg' => null, 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'destroy', 'descr' => 'Delete Record', 'module' => $feature_result['data']['module'], 'position' => 'table', 'url' => '/crm/' . $feature_result['data']['module'] . '/[ID]', 'icon' => 'fa-times', 'icon_bg' => 'btn-primary', 'page' => 'index', 'prompt_type' => 'confirm', 'prompt_title' => 'Delete', 'prompt_content' => 'Are you sure you wan to delete this record?'], ['feature_id' => $feature_result['data']['id'], 'name' => 'multi_destroy', 'descr' => 'Delete Multiple Record', 'module' => $feature_result['data']['module'], 'position' => 'panel-alert', 'url' => '/crm/' . $feature_result['data']['module'] . '/multi_destroy', 'icon' => 'fa-times', 'icon_bg' => 'btn-primary', 'page' => 'index', 'prompt_type' => 'confirm', 'prompt_title' => 'Delete', 'prompt_content' => 'Are you sure you wan to delete this record?']);
                 // foreach of the permission, insert into the db.
                 foreach ($permission_inputs as $permission_input) {
                     $permission = new Permission();
                     $permission_create = $permission->doCreate($permission_input, $permission_rules);
                     if ($permission_create['status'] != 1) {
                         throw new Exception($permission_create['message']);
                     }
                 }
             }
             #end if
             //if everything OK return success
             return Redirect::to('/crm/feature')->withMessage(Generate::message('SUCCESS', 'Success Create'));
         });
         #end transaction
     } catch (Exception $e) {
         return Redirect::to('/crm/feature')->withMessage(Generate::message('FAIL', $e->getMessage()));
     }
     return $new;
 }
开发者ID:vampirethura,项目名称:modelvillage,代码行数:40,代码来源:Feature.php

示例3: updateDocs

 /**
  * 資料を更新する
  * @param array $params
  */
 public static function updateDocs($params)
 {
     \DB::transaction(function () use($params) {
         \DB::table('events_docs')->where('id', '=', $params['id'])->update(['doc_type' => 1, 'docs_url' => $params['docsUrl']]);
     });
 }
开发者ID:suzumi,项目名称:giita,代码行数:10,代码来源:EventDoc.php

示例4: deleteStock

 /**
  * アンストックする
  * @param $params
  */
 public static function deleteStock($params)
 {
     \DB::transaction(function () use($params) {
         \DB::table('stocks')->where('user_id', '=', $params['userId'])->where('snippet_id', '=', $params['snippetId'])->delete();
     });
 }
开发者ID:suzumi,项目名称:giita,代码行数:10,代码来源:User.php


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