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


PHP DB::transaction方法代码示例

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


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

示例1: postContact

 public function postContact(Request $request)
 {
     $this->validate($request, ['name' => 'required|min:3', 'email' => 'required|email', 'content' => 'required|min:10']);
     \DB::transaction(function () use($request) {
         Contact::create($request->all());
     });
     session()->flash('message', ['success', 'Thanks for contacting us, we\'ve received your request, be with you soon!']);
     return redirect('/');
 }
开发者ID:optimatec,项目名称:cowork,代码行数:9,代码来源:FrontendController.php

示例2: cancel

 public function cancel(Request $request, $sn)
 {
     $refund = $this->resources->with('user', 'order')->where('user_id', '=', $request->user->id)->where('sn', '=', $sn)->firstOrFail();
     \DB::transaction(function () use($id, $request, $refund) {
         // 系统会自动退还可退还数量
         $refund->cancel()->logs()->save(new RefundLog(['do' => 'cancel', 'name' => $request->user->name, 'comment' => $request->json()->get('comment', '')]));
         $refund->order->total_refunded -= $refund->total_amount;
         if ($refund->order->order_status == Order::STATUS_BRANCHED) {
             $refund->order->branchRevert()->logs()->save(new OrderLog(['do' => 'branch_revert', 'name' => $request->user->name, 'comment' => 'branch revert']));
         } else {
             $refund->order->save();
         }
     });
     return response()->updated($refund);
 }
开发者ID:kshar1989,项目名称:dianpou,代码行数:15,代码来源:RefundController.php

示例3: createOrder

 public function createOrder(CreateOrderRequest $request)
 {
     $order = \DB::transaction(function () use($request) {
         $order = Order::create($request->all());
         $order->reference = \Hashids::encode($order->id);
         $order->save();
         foreach (\Cart::content() as $item) {
             $order->addItem($item);
         }
         return $order;
     });
     if ($order) {
         return response()->json(['success' => true, 'reference' => $order->reference], 200);
     }
     return response()->json(['success' => false]);
 }
开发者ID:stjanilofts,项目名称:kl,代码行数:16,代码来源:OrdersController.php

示例4: oauthCallback

 public function oauthCallback(Request $request)
 {
     if ($request->get('state') == session('state')) {
         $auth = new Auth(config('wechat.appid'), config('wechat.secret'));
         $ouser = $auth->user();
         if (!$ouser) {
             abort('微信授权错误 #13101');
         }
         $sa = SocialAccount::where('openid', $ouser->get('openid'))->where('platform', 'wechat')->first();
         if ($sa) {
             \Auth::loginUsingId($ouser->user_id);
         } else {
             \DB::transaction(function () use($ouser, $auth) {
                 $user = User::create(['name' => $ouser->get('nickname', ''), 'username' => $ouser->get('platform') . '_' . $ouser->get('openid', ''), 'avatar' => $ouser->get('headimgurl')]);
                 SocialAccount::create(['user_id' => $user->id, 'access_token' => $auth->access_token, 'refresh_token' => $auth->refresh_token, 'platform' => 'wechat', 'openid' => $ouser->get('openid'), 'user_info' => json_encode($ouser), 'union_id' => $ouser->get('union_id', '')]);
                 \Auth::loginUsingId($user->id);
             });
         }
         return redirect(route('home'));
     } else {
         abort('403', '服务器授权state不正确');
     }
 }
开发者ID:xuetumaster,项目名称:tpartner,代码行数:23,代码来源:WechatController.php

示例5: store

 /**
  * Create a new task.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->authorize('blog', Auth::user());
     $this->validate($request, Post::storeRules());
     $this->validate($request, Category::storeRules());
     $this->validate($request, Tag::storeRules());
     \DB::transaction(function () use($request) {
         $post = Post::create(Post::storeAttributes($request));
         $categories = explode(',', $request->categories);
         // remove empty items from array
         $categories = array_filter($categories);
         // trim all the items in array
         $categories = array_map('trim', $categories);
         $post->saveCategories($categories);
         $tags = explode(',', $request->tags);
         // remove empty items from array
         $tags = array_filter($tags);
         // trim all the items in array
         $tags = array_map('trim', $tags);
         $post->saveTags($tags);
     });
     return redirect(route('blog'));
 }
开发者ID:maiklez,项目名称:simpleapp,代码行数:29,代码来源:HomeController.php

示例6: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['title' => 'required|min:3', 'description' => 'min:3']);
     $category = Category::find($id);
     $old_title = $category->title;
     if ($category) {
         \DB::transaction(function () use($request, $category) {
             $category->translate()->title = $request->get('title');
             $category->translate()->description = $request->get('description');
             $category->parent_id = $request->get('parent_id');
             return $category->save();
         });
     }
     session()->flash('message', ['success', "Your category has been updated from <strong><i>" . $old_title . "</i></strong> to <strong><i>" . $category->title . "</i></strong>, successfully!"]);
     $categories = Category::with('translations')->paginate(10);
     return view('dashboard.categories.index', compact('categories'));
 }
开发者ID:optimatec,项目名称:cowork,代码行数:25,代码来源:CategoryController.php

示例7: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  Categories $category
  * @return Response
  */
 public function destroy(Category $category)
 {
     \DB::transaction(function () use($category) {
         $category->delete();
         $this->categoryPAndCObj->where('child_id', '=', $category->id)->orWhere('parent_id', '=', $category->id)->delete();
         \DB::table('member_categories')->where('category_id', '=', $category->id)->delete();
     });
     return Redirect::route('categories.index')->with('message', 'Category deleted.');
 }
开发者ID:nowarena,项目名称:homestead,代码行数:15,代码来源:CategoriesController.php

示例8: postFinishSignUp

 public function postFinishSignUp(SignUpFinish $req)
 {
     /** @var User $user */
     $user = unserialize(session('signup.user'));
     try {
         \DB::transaction(function () use($req, $user) {
             if ($req->email) {
                 $user->email = $req->email;
             }
             $user->username = $req->username;
             $user->throwOnValidation = true;
             //todo: https://github.com/laravel-ardent/ardent/issues/279
             $user->save();
             $this->saveLinks($user, true);
             $this->saveLinks($user);
             //those fields should not be "pulled" as an error might rise and their values can be reused in a 2nd try
             session()->remove('signup.user');
             session()->remove('signup.relations');
         });
     } catch (InvalidModelException $e) {
         return redirect()->action('AuthController@getSignUp')->with('social_error', true)->with('provider', $req->provider)->withErrors($e->getErrors());
     } catch (\Exception $e) {
         \Log::error(class_basename($e) . ' during social auth (' . printr($_GET) . '): [' . $e->getCode() . '] ' . $e->getMessage());
         return redirect()->action('AuthController@getSignUp')->with('social_error', true)->with('provider', $req->provider);
     }
     return $this->loginAfterSignUp($user, $req->provider);
 }
开发者ID:konato-events,项目名称:web,代码行数:27,代码来源:AuthController.php

示例9: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //make validations
     $validator = Validator::make($request->all(), ['name' => 'required', 'email' => 'array']);
     $validator->each('email', ['email']);
     if ($validator->fails()) {
         return redirect('room/create')->withErrors($validator)->withInput()->with('validation_err', true);
     }
     $room = new Room();
     $room->name = $request->input('name');
     $room->recording = empty($request->input('recording')) ? 0 : 1;
     $room->public = empty($request->input('public')) ? 0 : 1;
     $room->att_pass = Str::quickRandom(8);
     $room->mod_pass = Str::quickRandom(8);
     //add owner
     $user = Auth::User();
     $room->owner = $user->id;
     //check if meeting id exists
     \DB::transaction(function () use($room) {
         //check for unique access_pin and meeting id
         do {
             $bbb_meeting_id = Str::quickRandom(8);
         } while (Room::where('bbb_meeting_id', '=', $bbb_meeting_id)->count() != 0);
         do {
             $access_pin = mt_rand(0, 999999);
         } while (Room::where('access_pin', '=', $access_pin)->count() != 0);
         $room->bbb_meeting_id = $bbb_meeting_id;
         $room->access_pin = $access_pin;
         $room->save();
     });
     //extract emails
     /*$mails = preg_split('/\r\n|\n|\r/', $request->input('participants'));
     	$part_mails = array();
     	foreach($mails as $mail){
     		$part_mail = filter_var($mail, FILTER_VALIDATE_EMAIL);
     		if($part_mail){
     			$participant = new Participant();
     			$participant->mail = $part_mail;
     			$participant->room_id = $room->id;
     			$participant->save();
     		}
     	}*/
     $emails = $request->input('email');
     $moderators = $request->input('moderator');
     if (!$moderators) {
         $moderators = array();
     }
     if (is_array($emails)) {
         foreach ($emails as $email) {
             $participant = new Participant();
             $participant->mail = $email;
             $participant->room_id = $room->id;
             if (in_array($email, $moderators)) {
                 $participant->moderator = 1;
             }
             $participant->save();
         }
     }
     return Redirect::action('roomController@own');
 }
开发者ID:pkoro,项目名称:webconf-portal,代码行数:65,代码来源:roomController.php

示例10: save

 public function save(Request $request)
 {
     //     	sleep(2);
     //     	return response()->json('[]');
     // 		throw new Exception("not Save");
     $postData = $request->all();
     if (!array_key_exists('editedData', $postData) && !array_key_exists('deleteData', $postData)) {
         return response()->json('no data 2 update!');
     }
     if (!array_key_exists('editedData', $postData)) {
         $editedData = false;
     } else {
         $editedData = $postData['editedData'];
     }
     $facility_id = null;
     if (array_key_exists('Facility', $postData)) {
         $facility_id = $postData['Facility'];
     }
     $occur_date = null;
     if (array_key_exists('date_begin', $postData)) {
         $occur_date = $postData['date_begin'];
         $occur_date = \Helper::parseDate($occur_date);
     }
     $affectedIds = [];
     $this->preSave($editedData, $affectedIds, $postData);
     try {
         $resultTransaction = \DB::transaction(function () use($postData, $editedData, $affectedIds, $occur_date, $facility_id) {
             $this->deleteData($postData);
             if (!$editedData) {
                 return [];
             }
             $lockeds = [];
             $ids = [];
             $resultRecords = [];
             //      			\DB::enableQueryLog();
             foreach ($editedData as $mdlName => $mdlData) {
                 $modelName = $this->getModelName($mdlName, $postData);
                 $mdl = "App\\Models\\" . $modelName;
                 if ($mdl::$ignorePostData) {
                     unset($editedData[$mdlName]);
                     continue;
                 }
                 $ids[$mdlName] = [];
                 $resultRecords[$mdlName] = [];
                 $tableName = $mdl::getTableName();
                 $locked = \Helper::checkLockedTable($tableName, $occur_date, $facility_id);
                 if ($locked) {
                     $lockeds[$mdlName] = "Data of {$modelName} with facility {$facility_id} was locked on {$occur_date} ";
                     unset($editedData[$mdlName]);
                     continue;
                 }
                 foreach ($mdlData as $key => $newData) {
                     $columns = $mdl::getKeyColumns($newData, $occur_date, $postData);
                     $originNewData = $mdlData[$key];
                     $mdlData[$key] = $newData;
                     $returnRecord = $mdl::updateOrCreateWithCalculating($columns, $newData);
                     if ($returnRecord) {
                         $affectRecord = $returnRecord->updateDependRecords($occur_date, $originNewData, $postData);
                         $returnRecord->updateAudit($columns, $newData, $postData);
                         $ids[$mdlName][] = $returnRecord['ID'];
                         $resultRecords[$mdlName][] = $returnRecord;
                         if ($affectRecord) {
                             $ids[$mdlName][] = $affectRecord['ID'];
                             $resultRecords[$mdlName][] = $affectRecord;
                         }
                     }
                 }
                 $editedData[$mdlName] = $mdlData;
             }
             // 		     	\Log::info(\DB::getQueryLog());
             // 		     	$objectIds = array_unique($objectIds);
             //doFormula in config table
             $affectColumns = [];
             foreach ($editedData as $mdlName => $mdlData) {
                 $modelName = $this->getModelName($mdlName, $postData);
                 $cls = \FormulaHelpers::doFormula($modelName, 'ID', $ids[$mdlName]);
                 if (is_array($cls) && count($cls) > 0) {
                     $affectColumns[$mdlName] = $cls;
                 }
             }
             foreach ($resultRecords as $mdlName => $records) {
                 foreach ($records as $key => $returnRecord) {
                     $returnRecord->afterSaving($postData);
                 }
             }
             if ($this->isApplyFormulaAfterSaving) {
                 //get affected object with id
                 $objectWithformulas = [];
                 foreach ($editedData as $mdlName => $mdlData) {
                     $mdl = "App\\Models\\" . $mdlName;
                     foreach ($mdlData as $key => $newData) {
                         $columns = array_keys($newData);
                         if (array_key_exists($mdlName, $affectColumns)) {
                             $columns = array_merge($columns, $affectColumns[$mdlName]);
                         }
                         $uColumns = $mdl::getKeyColumns($newData, $occur_date, $postData);
                         $columns = array_diff($columns, $uColumns);
                         $aFormulas = $this->getAffectedObjects($mdlName, $columns, $newData);
                         $objectWithformulas = array_merge($objectWithformulas, $aFormulas);
                     }
//.........这里部分代码省略.........
开发者ID:hunglmtb,项目名称:eb,代码行数:101,代码来源:CodeController.php

示例11: postIndex

 /**
  * Create a new annotation.
  *
  * @param document ID $doc
  *
  * @throws Exception
  *
  * @return 303 redirect to annotation link
  */
 public function postIndex($doc)
 {
     $body = Input::all();
     $body['doc_id'] = $doc;
     $is_edit = false;
     //Check for edit tag
     if (in_array('edit', $body['tags'])) {
         $is_edit = true;
         //If no explanation present, throw error
         if (!isset($body['explanation'])) {
             throw new Exception('Explanation required for edits');
         }
     }
     $id = \DB::transaction(function () use($body, $doc, $is_edit) {
         $annotation = new Annotation();
         $annotation->doc_id = $doc;
         $annotation->user_id = Auth::user()->id;
         $annotation->quote = $body['quote'];
         $annotation->text = $body['text'];
         $annotation->uri = $body['uri'];
         $annotation->save();
         foreach ($body['ranges'] as $range) {
             $rangeObj = new AnnotationRange();
             $rangeObj->annotation_id = $annotation->id;
             $rangeObj->start_offset = $range['startOffset'];
             $rangeObj->end_offset = $range['endOffset'];
             $rangeObj->start = $range['start'];
             $rangeObj->end = $range['end'];
             $rangeObj->save();
         }
         $permissions = new AnnotationPermission();
         $permissions->annotation_id = $annotation->id;
         $permissions->user_id = Auth::user()->id;
         $permissions->read = 1;
         $permissions->update = 0;
         $permissions->delete = 0;
         $permissions->admin = 0;
         $permissions->save();
         foreach ($body['tags'] as $tag) {
             $tagObj = new AnnotationTag();
             $tagObj->annotation_id = $annotation->id;
             $tagObj->tag = $tag;
             $tagObj->save();
         }
         if ($is_edit) {
             $comment = new AnnotationComment();
             $comment->text = $body['explanation'];
             $comment->user_id = $annotation->user_id;
             $comment->annotation_id = $annotation->id;
             $comment->save();
         }
         //$annotation->updateSearchIndex();
         return $annotation->id;
     });
     $annotation = Annotation::find($id);
     Event::fire(MadisonEvent::DOC_ANNOTATED, $annotation);
     return Redirect::to('/api/docs/' . $doc . '/annotations/' . $id, 303);
 }
开发者ID:johnfelipe,项目名称:madison,代码行数:67,代码来源:AnnotationApiController.php

示例12: courseJudge

 /**
  * @param Request $request
  * @param Course $course
  * @return \Illuminate\Http\RedirectResponse
  */
 public function courseJudge(Request $request, Course $course)
 {
     $currentUser = Auth::getUser();
     if ($this->commentRepository->checkCourseCommented($currentUser->stu_id, $course->id) === true) {
         /* return to course page and show error  */
         return redirect()->to("/course/" . $course->id)->with(['error' => '您已經對該課程評鑑過囉!']);
     } else {
         /* comment confirm , call service calculate rank and call repository save course and comment */
         if ($this->courseService->validateJudgeRequest($request->all())) {
             \DB::transaction(function () use($course, $currentUser, $request) {
                 $comment = $this->commentRepository->createComment($course->id, $currentUser->stu_id, $request->all());
                 $this->courseService->UpdateCurrentRank($course, $comment);
             });
             return redirect()->to("/course/" . $course->id)->with(['success' => '恭喜完成評鑑!']);
         } else {
             return redirect()->back()->with(['error' => '尚有欄位沒填寫喔!']);
         }
     }
 }
开发者ID:e19940604,项目名称:Cyinf,代码行数:24,代码来源:CourseController.php

示例13: game_start

 public function game_start($id)
 {
     $game = \App\Models\Game::find($id);
     $players = \App\Models\Game_User::where('game_id', '=', $id)->get();
     $can_start = false;
     if ($game->min_players > $players->count()) {
         return redirect('games')->withWarning('Error, this game need more players to start.');
     }
     if ($game->started) {
         return redirect('games')->withWarning('Error, this game is already started.');
     }
     foreach ($players as $player) {
         if ($player->user_id == Auth::user()->id) {
             $can_start = true;
         }
     }
     $letters = \App\Models\Letter::all();
     \DB::transaction(function () use($letters, $id) {
         foreach ($letters as $letter) {
             $inventory = new \App\Models\Inventory_Letter_Game();
             $inventory->letter_id = $letter->id;
             $inventory->quantity = $letter->quantity;
             $inventory->game_id = $id;
             $inventory->save();
         }
     });
     $game->started = true;
     $game->save();
     \Event::fire(new \App\Events\GameStart($id));
     return redirect('gamejoin/' . $id);
 }
开发者ID:AndrewJey,项目名称:IIProyecto-Soft.Libre--Scrabble,代码行数:31,代码来源:GameController.php

示例14: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(MemberEntity $memberEnt)
 {
     \DB::transaction(function () use($memberEnt) {
         \DB::table('member_categories')->where('member_id', '=', $memberEnt->id)->delete();
         \DB::table('member_social_ids')->where('member_id', '=', $memberEnt->id)->delete();
         \DB::table('social_media')->where('member_id', '=', $memberEnt->id)->delete();
         \DB::table('instagram_location_ids')->where('member_id', '=', $memberEnt->id)->delete();
         \DB::table('members')->where('id', '=', $memberEnt->id)->delete();
     });
     return Redirect::route('members.index')->with('message', 'Member deleted.');
 }
开发者ID:nowarena,项目名称:homestead,代码行数:17,代码来源:MembersController.php

示例15: saveDocumentEdits

 public function saveDocumentEdits($documentId)
 {
     if (!Auth::check()) {
         return Redirect::to('documents')->with('error', 'You must be logged in');
     }
     $content = Input::get('content');
     $contentId = Input::get('content_id');
     if (empty($content)) {
         return Redirect::to('documents')->with('error', "You must provide content to save");
     }
     if (!empty($contentId)) {
         $docContent = DocContent::find($contentId);
     } else {
         $docContent = new DocContent();
     }
     if (!$docContent instanceof DocContent) {
         return Redirect::to('documents')->with('error', 'Could not locate document to save');
     }
     $document = Doc::find($documentId);
     if (!$document instanceof Doc) {
         return Redirect::to('documents')->with('error', "Could not locate the document");
     }
     if (!$document->canUserEdit(Auth::user())) {
         return Redirect::to('documents')->with('error', 'You are not authorized to save that document.');
     }
     $docContent->doc_id = $documentId;
     $docContent->content = $content;
     try {
         \DB::transaction(function () use($docContent, $content, $documentId, $document) {
             $docContent->save();
         });
     } catch (\Exception $e) {
         return Redirect::to('documents')->with('error', "There was an error saving the document: {$e->getMessage()}");
     }
     //Fire document edited event for admin notifications
     $doc = Doc::find($docContent->doc_id);
     Event::fire(MadisonEvent::DOC_EDITED, $doc);
     try {
         $document->indexContent($docContent);
     } catch (\Exception $e) {
         return Redirect::to('documents')->with('error', "Document saved, but there was an error with Elasticsearch: {$e->getMessage()}");
     }
     return Redirect::to('documents')->with('success_message', 'Document Saved Successfully');
 }
开发者ID:st421,项目名称:madison,代码行数:44,代码来源:DocumentsController.php


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