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(); } }
/** * 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(); } }
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; }
/** * 結帳後負責更新資料庫 * * @param $id */ public function checkout($id) { DB::transaction(function () use($id) { $productId = $this->orderRepository->updateStatusToY($id); $this->productRepository->stockMinusOne($productId); }); }
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'); } }
/** * 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); }); }
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; }
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; }); }
/** * 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'); }); }
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; }
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(); } }
/** * @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; }
/** * Truncate organization tables */ public function truncate() { DB::transaction(function () { DB::table('relations')->delete(); DB::table('organizations')->delete(); }); }
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(); }
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); }
/** * Saving new password. * * @param \Orchestra\Model\User $user * @param array $input */ protected function saving(Eloquent $user, array $input) { $user->setAttribute('password', $input['new_password']); DB::transaction(function () use($user) { $user->save(); }); }
public function createAction() { $model = new Evaluation(); $input = Input::all(); $validator = $model->validateInput($input); if ($validator->fails()) { app()->abort(422, $validator->errors()->first()); } $audits = Input::get("auditResult"); foreach ($audits as $audit) { DB::transaction(function () use($model, $audit) { $assertion = new Assertion(["date" => new Carbon(), "mode" => $audit["mode"], "test_id" => $audit["test"]["@id"], "test_type" => $audit["test"]["@type"], "result_type" => $audit["result"]["@type"], "result_outcome" => $audit["result"]["outcome"]]); /** @var Assertor $assertor */ $assertor = Assertor::find(LDModel::getIdFromLdId(Input::get("creator.@id"))); $model->fill(["date" => new Carbon()]); $model->creator()->associate($assertor); $model->save(); /** @var Webpage $subject */ $subject = Webpage::find(LDModel::getIdFromLdId($audit["subject"])); if (!$subject) { app()->abort(422, "Subject not found"); } $assertion->assertor()->associate($assertor); $assertion->subject()->associate($subject); $assertion->evaluation()->associate($model); $assertion->save(); }); } return $this->response($model); }
public static function import() { DB::transaction(function () { $referats = ReferatParser::parse(public_path() . '/data/' . 'abstracts_import.xlsx'); self::process($referats); //throw new Exception('Some test exception'); }); }
public function update(array $data, $id) { DB::transaction(function () use($data, $id) { $node = $this->updateData($data, $id); // $node->parents()->updateExistingPivot($node->id,['node_parent_id'=>$data['node_parent_id']]); DB::table('node_hierarchy')->where('node_id', $node->id)->update(['node_parent_id' => $data['node_parent_id']]); }); }
/** * Create a new user instance after a valid registration. * And now, include profiles * * @param array $data * @return User */ protected function create(array $data) { return DB::transaction(function () use($data) { $userModel = User::create(['code' => md5($data['email']), 'email' => $data['email'], 'password' => bcrypt($data['password'])]); $userModel->profile()->create([]); return $userModel; }); }
/** * {@inheritdoc} */ public function insert(array $rows) { DB::transaction(function () use($rows) { foreach ($rows as $row) { $this->insertRow($row); } }); }
/** * Reverse the migrations. * * @return void */ public function down() { DB::transaction(function () { Schema::drop('menu_permission'); Schema::drop('menus'); Schema::drop('navigation'); }); }
/** * Reverse the migrations. * * @return void */ public function down() { DB::transaction(function () { Schema::drop('widget_menu'); Schema::drop('widget_permission'); Schema::drop('widgets'); }); }
public function update(Request $request, $id) { DB::transaction(function () use($request, $id) { $role = Role::find($id); $role->update($request->only('name', 'display_name', 'description')); flash()->success('Data peran berhasil diperbarui.'); }); return redirect()->back(); }
/** * Handle the command. * * @param CreateClientUserCommand $command * @return void */ public function handle(CreateClientUserCommand $command) { //If photo uploaded correctly //Create user and client in DB DB::transaction(function () use($command) { $user = User::create(['email' => $command->email, 'password' => $command->password]); $client = Client::create(['profile_photo' => $command->profile_photo, 'first_name' => $command->first_name, 'last_name' => $command->last_name, 'user_id' => $user->id, 'email' => $command->email, 'phone_1' => $command->phone_1, 'phone_2' => $command->phone_2, 'address_1' => $command->address_1, 'address_2' => $command->address_2, 'city' => $command->city, 'state' => $command->state, 'zip' => $command->zip]); }); }
/** * Remove the specified resource from storage. * * @param Product $product * @param Stock $stock * @return \Illuminate\Http\Response */ public function destroy(Product $product, Stock $stock) { $product = DB::transaction(function () use($product, $stock) { $stock->delete(); $product->updateStock(); return $product; }); return redirect()->route('product.show', $product); }
public function create() { DB::transaction(function () { $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Article, 'subtype' => MissionControlSubtype::PressRelease, 'title' => $this->input['title'], 'size' => strlen($this->input['article']), 'article' => $this->input['article'], 'cryptographic_hash' => hash('sha256', $this->input['article']), 'originated_at' => \Carbon\Carbon::now(), 'publisher_id' => Publisher::where('name', 'SpaceX')->first()->publisher_id, 'status' => ObjectPublicationStatus::QueuedStatus]); $this->createMissionRelation(); $this->createTagRelations(); $this->object->push(); }); return $this->object; }
public function create() { DB::transaction(function () { $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Comment, 'subtype' => MissionControlSubtype::NSFComment, 'title' => $this->input['title'], 'size' => strlen($this->input['comment']), 'summary' => $this->input['comment'], 'cryptographic_hash' => hash('sha256', $this->input['comment']), 'external_url' => $this->input['external_url'], 'originated_at' => \Carbon\Carbon::now(), 'status' => ObjectPublicationStatus::QueuedStatus]); $this->createMissionRelation(); $this->createTagRelations(); $this->object->push(); }); return $this->object; }
public function create() { DB::transaction(function () { $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Text, 'title' => $this->input['title'], 'size' => strlen($this->input['summary']), 'summary' => $this->input['summary'], 'anonymous' => array_get($this->input, 'anonymous', false), 'cryptographic_hash' => hash('sha256', $this->input['summary']), 'originated_at' => Carbon::now(), 'original_content' => true, 'status' => ObjectPublicationStatus::QueuedStatus]); $this->createMissionRelation(); $this->createTagRelations(); $this->object->push(); }); return $this->object; }
public static function import() { DB::transaction(function () { $lines = file(public_path() . '/data/' . 'zmist.txt'); $lines = self::clean($lines); $editionId = EditionImporter::importEdition($lines[0]); self::process(array_slice($lines, 1), $editionId, 1); //throw new Exception('Some test exception'); }); }