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


PHP DB::transaction方法代码示例

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


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

示例1: createSupply

    public static function createSupply(){
    	$validator = self::validator();
    	if($validator->fails()){
    		return back()->withErrors($validator->errors())->withInput();
    	}

        DB::transaction(function() use(&$vehicle) {
            $supply = Supply::create([
                'type_id'   => 2,
                'title'     =>request('title'),
                'images'    =>request('images'),
                'user_id'   =>User::user()->id,
                'desc'      =>request('desc'),
                'stage'     => 2,
            ]);

            $vehicle = new self(request()->all());
            $vehicle = $supply->vehicle()->save($vehicle);
        });

        if ($vehicle != null) {
            return redirect('user/supply');
        } else {
            return back()->withErrors('创建失败')->withInput();
        }
    }
开发者ID:xinray,项目名称:html-css,代码行数:26,代码来源:Vehicle.php

示例2: postEntrepriseProfil

 /**
  * Traitement du formulaire de profil
  *
  * @return Redirect
  */
 public function postEntrepriseProfil(ProfilEntrepriseRequest $request)
 {
     $entreprise = Entreprise::find(Auth::user()->user->id);
     $entreprise->nom = Input::get('nom');
     $entreprise->description = Input::get('description');
     $entreprise->siret = Input::get('siret');
     $entreprise->taille = Input::get('taille');
     $entreprise->lieu = Input::get('lieu');
     $entreprise->fax = Input::get('fax');
     $entreprise->secteur = Input::get('secteur');
     $entreprise->telephone = Input::get('telephone');
     $entreprise->sociaux = Input::get('sociaux');
     $entreprise->site = Input::get('site');
     /* La transaction permet d'englober un ensemble d'actions. Soit l'ensemble se termine,
        soit l'ensemble de ces actions sont annulées */
     DB::transaction(function () use($request, $entreprise) {
         if ($request->hasFile('logo')) {
             $file = $request->file('logo');
             $ext = $file->getClientOriginalExtension();
             $logo = 'logo.' . $ext;
             $file->move('uploads/entreprises/' . $entreprise->nom, $logo);
             $entreprise->logo = $logo;
         }
     });
     if ($entreprise->save()) {
         return Redirect::refresh()->with('flash_success', 'Modification Profil enregistré!')->withInput();
     }
 }
开发者ID:Anassdev,项目名称:AdopteUnStage,代码行数:33,代码来源:EntrepriseProfilController.php

示例3: process

 function process($saleId, $statusId)
 {
     $response = new ResponseEntity();
     try {
         DB::transaction(function () use(&$response, $saleId, $statusId) {
             $sale = Sale::find($saleId);
             if ($sale) {
                 $sale->qc_user_id = Auth::user()->id;
                 $sale->sale_status_id = $statusId;
                 $sale->verified = 1;
                 $ok = $sale->save();
                 if ($ok) {
                     $ok = $this->setIncentive($sale->user_id, $sale->date_sold);
                     $response->setMessages($ok ? ['Sale successfully processed!'] : ['Failed to process sale!']);
                     $response->setSuccess($ok);
                 } else {
                     $response->setMessages(['Failed to process sale!']);
                 }
             } else {
                 $response->setMessages(['Sale not available']);
             }
         });
     } catch (\Exception $ex) {
         $response->setMessages(['Exception: ' . $ex->getMessage()]);
     }
     return $response;
 }
开发者ID:arjayads,项目名称:green-tracker,代码行数:27,代码来源:SaleService.php

示例4: checkout

 /**
  * 結帳後負責更新資料庫
  *
  * @param $id
  */
 public function checkout($id)
 {
     DB::transaction(function () use($id) {
         $productId = $this->orderRepository->updateStatusToY($id);
         $this->productRepository->stockMinusOne($productId);
     });
 }
开发者ID:oomusou,项目名称:Laravel51ServiceMultiRepository_demo,代码行数:12,代码来源:OrderService.php

示例5: TambahJadwal

 public function TambahJadwal()
 {
     $rules = array('unit_id' => 'required', 'kategori' => 'required', 'tglstart' => 'required', 'tglases' => 'required', 'tglfinish' => 'required', 'detail' => 'required');
     $messages = array('unit_id.required' => 'Nama Jabatan Harus Terisi', 'kategori.required' => 'Kategori Harus Dipilih', 'tglstart.required' => 'Tanggal Mulai Harus Terisi', 'tglases.required' => 'Tanggal Asessment Harus Terisi', 'tglfinish.required' => 'Tanggal Selesai Harus Terisi', 'detail.required' => 'Detail Harus terisi');
     $validasi = validator::make(Input::all(), $rules, $messages);
     if ($validasi->fails()) {
         return Redirect::back()->withErrors($validasi)->withInput();
     } else {
         $kat = Input::get('kategori');
         if ($kat == 'internal') {
             $aa = "in";
         } else {
             $aa = "ex";
         }
         DB::transaction(function ($aa) use($aa) {
             //asesment promosi
             $jadwal = KandidatPromote::create(['unit_staf_id' => Input::get('unit_id'), 'tgl_awal' => Input::get('tglstart'), 'tgl_asesment' => Input::get('tglases'), 'tgl_selesai' => Input::get('tglfinish'), 'detail' => Input::get('detail')]);
             //rekrutmen rekap header
             $rekap_header = HeaderRekap::create(['id_asesmen' => $jadwal->id, 'kategori' => Input::get('kategori'), 'nama' => Input::get('jabatan'), 'tanggal_awal' => Input::get('tglstart'), 'tanggal_akhir' => Input::get('tglfinish'), 'deksripsi' => Input::get('detail')]);
             //asessment promosi daftar
             $daftar = KandidatPromosiDaftar::create(['asesment_promosi_id' => $jadwal->id, 'nip' => Input::get('nip'), 'detail' => Input::get('detail')]);
             //rekrutment rekap profiling
             $profil = ProfilingRekap::create(['id_rekap' => $rekap_header->id, 'kategori' => $aa, 'nip' => $daftar->nip, 'id_jabatan' => $jadwal->unit_staf_id]);
         });
         Session::flash('message', 'Berhasil Menambahkan Jadwal Asessment');
         return Redirect::to('career/jadwal/lihat/asessment');
     }
 }
开发者ID:hendrilara,项目名称:kemenpan,代码行数:28,代码来源:KandidatPromosiController.php

示例6: balances

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function balances($address_uuid, Guard $auth, Request $request, APIControllerHelper $helper, AccountRepository $account_respository, PaymentAddressRepository $payment_address_repository, LedgerEntryRepository $ledger_entry_repository)
 {
     return DB::transaction(function () use($address_uuid, $auth, $request, $helper, $account_respository, $payment_address_repository, $ledger_entry_repository) {
         $user = $auth->getUser();
         if (!$user) {
             throw new Exception("User not found", 1);
         }
         $payment_address = $helper->requireResourceOwnedByUser($address_uuid, $user, $payment_address_repository);
         $resources = $account_respository->findByAddressAndUserID($payment_address['id'], $user['id'], $this->buildAccountFilter($request, $account_respository));
         // get a (valid) type
         $type = null;
         if (strlen($type_string = $request->input('type'))) {
             try {
                 $type = LedgerEntry::typeStringToInteger($type_string);
             } catch (Exception $e) {
                 return $helper->buildJSONResponse(['message' => 'bad type parameter'], 400);
             }
         }
         // add the balances to each one
         $accounts_with_balances = [];
         foreach ($resources as $account) {
             $account_and_balances = $account->serializeForAPI();
             $balances = $ledger_entry_repository->accountBalancesByAsset($account, $type);
             $account_and_balances['balances'] = $balances;
             $accounts_with_balances[] = $account_and_balances;
         }
         return $helper->buildJSONResponse($accounts_with_balances);
     });
 }
开发者ID:CryptArc,项目名称:xchain,代码行数:34,代码来源:AccountBalancesController.php

示例7: love

 function love(array $params)
 {
     $response = new ResponseEntity();
     DB::transaction(function () use(&$response, $params) {
         if ($params['postId']) {
             $ep = Post::find($params['postId']);
             if (!$ep) {
                 $response->setMessages(['Post is not available']);
             } else {
                 $p = new PostLove();
                 $p->post_id = $params['postId'];
                 $p->user_id = Auth::user()->id;
                 $ok = $p->save();
                 if ($ok) {
                     $response->setSuccess(true);
                 } else {
                     $response->setMessages(['Something went wrong!']);
                 }
             }
         } else {
             $response->setMessages(['Post is not available']);
         }
     });
     return $response;
 }
开发者ID:arjayads,项目名称:green-tracker,代码行数:25,代码来源:PostService.php

示例8: checkout

 public function checkout($attributes)
 {
     return DB::transaction(function ($attributes) use($attributes) {
         $shipping_address_same_as_billing_address = array_get($attributes, 'shipping_address_same_as_billing_address', false);
         if ($shipping_address_same_as_billing_address) {
             array_set($attributes, 'shipping_address_first_name', array_get($attributes, 'billing_address_first_name'));
             array_set($attributes, 'shipping_address_last_name', array_get($attributes, 'billing_address_last_name'));
             array_set($attributes, 'shipping_address_company', array_get($attributes, 'billing_address_company'));
             array_set($attributes, 'shipping_address_address_1', array_get($attributes, 'billing_address_address_1'));
             array_set($attributes, 'shipping_address_address_2', array_get($attributes, 'billing_address_address_2'));
             array_set($attributes, 'shipping_address_city', array_get($attributes, 'billing_address_city'));
             array_set($attributes, 'shipping_address_postal_code', array_get($attributes, 'billing_address_postal_code'));
             array_set($attributes, 'shipping_address_country_id', array_get($attributes, 'billing_address_country_id'));
             array_set($attributes, 'shipping_address_zone_id', array_get($attributes, 'billing_address_zone_id'));
         }
         $order = $this->create($attributes);
         //add line items
         $line_items = [];
         foreach (array_get($attributes, 'line_items', []) as $line_item) {
             $line_items[] = new LineItem($line_item);
         }
         $order->lineItems()->saveMany($line_items);
         //add totals
         $totals = [];
         foreach (array_get($attributes, 'totals', []) as $total) {
             $totals[] = new OrderTotal($total);
         }
         $order->totals()->saveMany($totals);
         return $order;
     });
 }
开发者ID:pda-code,项目名称:eshop-angular-laravel,代码行数:31,代码来源:OrderService.php

示例9: up

 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     DB::transaction(function () {
         DB::statement("create temporary table unique_entities (select e.id as orig_id, e.name as name, (select min(id) from entities where entities.name=e.name) as uniq_id from entities as e);");
         $pairs = DB::select("select orig_id, uniq_id from unique_entities where orig_id != uniq_id;");
         $oldToUnique = [];
         foreach ($pairs as $pair) {
             $oldToUnique[$pair->orig_id] = $pair->uniq_id;
         }
         $charts = Chart::all();
         foreach ($charts as $chart) {
             $config = json_decode($chart->config);
             $countries = $config->{'selected-countries'};
             if (empty($countries)) {
                 continue;
             }
             foreach ($countries as $country) {
                 if (array_key_exists($country->id, $oldToUnique)) {
                     echo "Updating chart config for " . $chart->id . " changing entity id from " . $country->id . " to " . $oldToUnique[$country->id] . "\n";
                     $country->id = $oldToUnique[$country->id];
                 }
             }
             $chart->config = json_encode($config);
             $chart->save();
         }
         DB::statement("update data_values as dv inner join unique_entities as e on e.orig_id=dv.fk_ent_id set dv.fk_ent_id=e.uniq_id;");
         DB::statement("delete from entities where entities.id in (select orig_id from unique_entities where orig_id != uniq_id);");
         DB::statement("drop table unique_entities;");
     });
     Schema::table("entities", function ($table) {
         $table->unique('name');
     });
 }
开发者ID:mispy,项目名称:our-world-in-data-grapher,代码行数:38,代码来源:2016_03_29_105205_entity_uniqueness.php

示例10: create

 public function create()
 {
     DB::transaction(function () {
         $twitterClient = new TwitterOAuth(Config::get('services.twitter.consumerKey'), Config::get('services.twitter.consumerSecret'), Config::get('services.twitter.accessToken'), Config::get('services.twitter.accessSecret'));
         // Fetch the tweet information from Twitter, if a tweet id was passed through (it is possible the tweet was created manually without an id)
         if (array_key_exists('tweet_id', $this->input)) {
             $tweet = $twitterClient->get('statuses/show', ['id' => $this->input['tweet_id']]);
             $tweetOwner = $tweet->user;
             $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $tweet->text, 'tweet_id' => $tweet->id, 'tweet_parent_id' => $tweet->in_reply_to_status_id, 'size' => strlen($tweet->text), 'title' => $tweet->text, 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $tweet->text), 'originated_at' => Carbon::createFromFormat('D M d H:i:s P Y', $tweet->created_at)->toDateTimeString(), 'status' => ObjectPublicationStatus::QueuedStatus]);
         } else {
             $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $this->input['tweet_text'], 'size' => strlen($this->input['tweet_text']), 'title' => $this->input['tweet_text'], 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $this->input['tweet_text']), 'originated_at' => $this->input['originated_at'], 'status' => ObjectPublicationStatus::QueuedStatus]);
         }
         try {
             if (!isset($tweetOwner)) {
                 $tweetOwner = $twitterClient->get('users/show', ['screen_name' => $this->input['tweet_screen_name']]);
             }
             $tweeter = Tweeter::byScreenName($tweetOwner->screen_name)->firstOrFail();
         } catch (ModelNotFoundException $e) {
             $tweeter = Tweeter::create(['screen_name' => $tweetOwner->screen_name, 'user_name' => $tweetOwner->name, 'description' => $tweetOwner->description]);
             $tweeter->saveProfilePicture();
         }
         $this->object->tweeter()->associate($tweeter);
         $this->createMissionRelation();
         $this->createTagRelations();
         $this->object->push();
     });
     return $this->object;
 }
开发者ID:RoryStolzenberg,项目名称:spacexstats,代码行数:28,代码来源:ObjectFromTweet.php

示例11: mapping

 public function mapping($id, Request $request)
 {
     $workflow = Workflow::find($id);
     if ($request->isMethod('get')) {
         $workflow->load('menus');
         $title = 'Pemetaan Proses Aliran Kerja';
         $roles = Role::get()->pluck('display_name', 'id');
         $menus = Menu::get()->pluck('name', 'id');
         return view('profio/auth::workflow.mapping', compact('workflow', 'title', 'roles', 'menus'));
     } else {
         $workflow->menus()->detach();
         $workflow->permissions()->detach();
         $role_ids = $request->input('role_ids');
         $menu_ids = $request->input('menu_ids');
         DB::transaction(function () use($role_ids, $workflow, $menu_ids) {
             foreach ($role_ids as $key => $role_id) {
                 $workflow->menus()->attach($menu_ids[$key], ['role_id' => $role_id]);
                 $menu = Menu::find($menu_ids[$key]);
                 foreach ($menu->permissions as $permission) {
                     $workflow->permissions()->attach($permission->id, ['role_id' => $role_id]);
                 }
             }
             flash()->success('Pemetaan proses aliran kerja berhasil disimpan.');
         });
         return redirect()->back();
     }
 }
开发者ID:profio,项目名称:auth,代码行数:27,代码来源:WorkflowController.php

示例12: create

 /**
  * @param array $data
  * @param bool $provider
  * @return static
  */
 public function create(array $data, $provider = false)
 {
     $user = self::MODEL;
     $user = new $user();
     $user->name = $data['name'];
     $user->email = $data['email'];
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->status = 1;
     $user->password = $provider ? null : bcrypt($data['password']);
     $user->confirmed = $provider ? 1 : (config('access.users.confirm_email') ? 0 : 1);
     DB::transaction(function () use($user) {
         if (parent::save($user)) {
             /**
              * Add the default site role to the new user
              */
             $user->attachRole($this->role->getDefaultUserRole());
         }
     });
     /**
      * If users have to confirm their email and this is not a social account,
      * send the confirmation email
      *
      * If this is a social account they are confirmed through the social provider by default
      */
     if (config('access.users.confirm_email') && $provider === false) {
         $user->notify(new UserNeedsConfirmation($user->confirmation_code));
     }
     /**
      * Return the user object
      */
     return $user;
 }
开发者ID:rappasoft,项目名称:laravel-5-boilerplate,代码行数:37,代码来源:UserRepository.php

示例13: truncate

 /**
  * Truncate organization tables
  */
 public function truncate()
 {
     DB::transaction(function () {
         DB::table('relations')->delete();
         DB::table('organizations')->delete();
     });
 }
开发者ID:anroots,项目名称:dag,代码行数:10,代码来源:Organization.php

示例14: updateCareerHistory

 public function updateCareerHistory(Request $request)
 {
     $validator = Validator::make($request->all(), []);
     DB::transaction(function () use($request) {
         $managerProfile = ManagerProfile::where('user_id', '=', session(SiteSessions::USER_ID))->first();
         $managerProfile->institution_type = $request->institution_type;
         $managerProfile->institution_name = $request->institution_name;
         $managerProfile->save();
         $careerHistories = $request->careerHistory;
         foreach ($careerHistories as $careerHistory) {
             $managerCareerHistory = null;
             //Checking if career history already exists
             if ($managerCareerHistory = ManagerCareerHistory::CareerHistoryExists($managerProfile->profile_id, $careerHistory["year"])) {
             } else {
                 $managerCareerHistory = ManagerCareerHistory::create(['profile_id' => $managerProfile->profile_id, 'career_year' => $careerHistory["year"]]);
             }
             $achievements = $careerHistory["achievement"];
             foreach ($achievements as $achievement) {
                 //Checking if Achievement already exists for Career History
                 if (ManagerCareerHistoryAchievement::AchievementExists($managerCareerHistory->id, $achievement["info"])) {
                 } else {
                     $managerCareerHistory->Achievements()->save(new ManagerCareerHistoryAchievement(['achievement' => $achievement["info"]]));
                 }
             }
             //Removing Obselete Achievements
             ManagerCareerHistoryAchievement::RemoveObseleteAchievement($managerCareerHistory, $achievements);
         }
         ManagerCareerHistory::RemoveObseleteCareerHistory($managerProfile, $careerHistories);
     });
     $this->sendResponse();
 }
开发者ID:piyushsh,项目名称:talenthub-website,代码行数:31,代码来源:ManagerCareerHistoryController.php

示例15: update

 public function update(SubscriptionService $subscriptionService, DeltaVCalculator $deltaV, $object_id)
 {
     if (Input::has(['status', 'visibility'])) {
         $object = Object::find($object_id);
         if (Input::get('status') == ObjectPublicationStatus::PublishedStatus) {
             DB::transaction(function () use($object, $subscriptionService, $deltaV) {
                 // Put the necessary files to S3 (and maybe local)
                 if (Input::get('visibility') == VisibilityStatus::PublicStatus) {
                     $object->putToLocal();
                 }
                 $job = (new PutObjectToCloudJob($object))->onQueue('uploads');
                 $this->dispatch($job);
                 // Update the object properties
                 $object->fill(Input::only(['status', 'visibility']));
                 $object->actioned_at = Carbon::now();
                 // Save the object if there's no errors
                 $object->save();
                 // Add the object to our elasticsearch node
                 Search::index($object->search());
                 // Create an award wih DeltaV
                 $award = Award::create(['user_id' => $object->user_id, 'object_id' => $object->object_id, 'type' => 'Created', 'value' => $deltaV->calculate($object)]);
                 // Once done, extend subscription
                 $subscriptionService->incrementSubscription($object->user, $award);
             });
         } elseif (Input::get('status') == "Deleted") {
             $object->delete();
         }
         return response()->json(null, 204);
     }
     return response()->json(false, 400);
 }
开发者ID:RoryStolzenberg,项目名称:spacexstats,代码行数:31,代码来源:ReviewController.php


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