本文整理汇总了PHP中Illuminate\Support\Facades\DB::rollback方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::rollback方法的具体用法?PHP DB::rollback怎么用?PHP DB::rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\DB
的用法示例。
在下文中一共展示了DB::rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: store
/**
* Store a newly created employee in storage
*/
public function store()
{
$validator = Validator::make($input = Input::all(), Personal::rules('create'));
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
DB::beginTransaction();
try {
$nombres = $input['nombres'];
$apellidos = $input['apellidos'];
$filename = null;
// Profile Image Upload
if (Input::hasFile('fotoPersonal')) {
return "gola a todos";
$path = public_path() . "/foto/";
File::makeDirectory($path, $mode = 0777, true, true);
$image = Input::file('fotoPersonal');
$extension = $image->getClientOriginalExtension();
$filename = "{$nombres}_{$input['personalID']}." . strtolower($extension);
Image::make($image->getRealPath())->fit(872, 724, function ($constraint) {
$constraint->upsize();
})->save($path . $filename);
}
$tipo = "Aportante";
// return Input::all();
Personal::create(['personalID' => $input['personalID'], 'emision' => $input['nitcit2'], 'nombres' => ucwords(strtolower($input['nombres'])), 'apellidos' => ucwords(strtolower($input['apellidos'])), 'email' => $input['email'], 'password' => Hash::make($input['password']), 'genero' => $input['genero'], 'tipoPersonal' => $tipo, 'telefono' => $input['telefono'], 'fotoPersonal' => isset($filename) ? $filename : 'default.jpg']);
Activity::log(['contentId' => $input['personalID'], 'contentType' => 'Personal Aportante', 'user_id' => Auth::admin()->get()->id, 'action' => 'Creando Un Aportante', 'description' => 'Creacion ' . $tipo, 'details' => 'Usuario: ' . Auth::admin()->get()->name, 'updated' => $input['personalID'] ? true : false]);
// return Input::all();
} catch (\Exception $e) {
DB::rollback();
throw $e;
}
DB::commit();
return Redirect::route('admin.personal.index')->with('success', "<strong>{$nombres}</strong> exitosamente adicionado en le base de datos");
}
示例3: create
public function create(array $data)
{
DB::beginTransaction;
// $this->db::
try {
$data['status'] = 0;
if (isset($data['cupom_code'])) {
$cupom = $this->cupomRepository->findByField('code', $data['cupom_code'])->first();
$data['cupom_id'] = $cupom->id;
$cupom->used = 1;
$cupom->save();
unset($data['cupom_code']);
}
$items = $data['items'];
unset($data['items']);
$order = $this->repository->create($data);
$total = 0;
foreach ($items as $item) {
$item['price'] = $this->productRepository->find($item['product_id'])->price;
$order->items()->create($item);
$total += $item['price'] * $item['qtd'];
}
$order->total = $total;
if (isset($cupom)) {
$order->total = $total - $cupom->value;
}
$order->save();
DB::commit();
} catch (\Exception $e) {
DB::rollback();
throw $e;
}
}
示例4: 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!');
}
}
示例5: createResourceCallable
/**
* @return callable
*/
protected function createResourceCallable()
{
$createOrderResource = function (Model $model, array $data) {
if (!empty($data['relationships']['order']['data'])) {
$orderData = $data['relationships']['order']['data'];
if (!empty($orderData['type'])) {
$orderData = [$orderData];
}
foreach ($orderData as $order) {
$attributes = array_merge($order['attributes'], ['employee_id' => $model->getKey()]);
Orders::create($attributes);
}
}
};
return function (array $data, array $values, ErrorBag $errorBag) use($createOrderResource) {
$attributes = [];
foreach ($values as $name => $value) {
$attributes[$name] = $value;
}
if (!empty($data['id'])) {
$attributes[$this->getDataModel()->getKeyName()] = $values['id'];
}
DB::beginTransaction();
try {
$model = $this->getDataModel()->create($attributes);
$createOrderResource($model, $data);
DB::commit();
return $model;
} catch (\Exception $e) {
DB::rollback();
$errorBag[] = new Error('creation_error', 'Resource could not be created');
throw new \Exception();
}
};
}
示例6: updateBuiltTickets
/**
* Update tickets from built plan
*
* @param $planId
* @param $ticketsData
* @return bool
*/
public function updateBuiltTickets($planId, $ticketsData)
{
$redirect = false;
$errorMsg = '';
// Start transaction
DB::beginTransaction();
// Start tickets update
try {
$ticket = $this->model->where('plan_id', '=', $planId);
$ticket->update(['tickets' => serialize($ticketsData)]);
} catch (\Exception $e) {
$errorMsg = $e->getMessage();
$redirect = true;
} catch (QueryException $e) {
$errorMsg = $e->getErrors();
$redirect = true;
} catch (ModelNotFoundException $e) {
$errorMsg = $e->getErrors();
$redirect = true;
}
// Redirect if errors
if ($redirect) {
// Rollback
DB::rollback();
// Log to system
Tools::log($errorMsg, $ticketsData);
return false;
}
// Commit all changes
DB::commit();
return true;
}
示例7: postRegister
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postRegister(Request $request)
{
if (!$request->ajax()) {
return JsonHelper::invalidRequest();
}
$flag = ForbiddenUsername::getInstance()->checkName($request->request->get('username'));
if ($flag) {
return JsonHelper::json('', '用户名非法!', 40002);
}
$validator = $this->registrar->validator($request->all());
if ($validator->fails()) {
return JsonHelper::json('', $validator->messages(), 50001);
}
try {
$this->auth->login($this->registrar->create($request->all()));
DB::commit();
return JsonHelper::json('', 'register success', 10000);
} catch (DevBaseException $e) {
DB::rollback();
if (config('app.debug')) {
var_export($e->getMessage());
exit;
}
return JsonHelper::InternalDbFail();
}
}
示例8: add
function add(array $request, $lead_id)
{
DB::beginTransaction();
try {
$application_id = Application::select('id')->where('ex_lead_id', $lead_id)->first()->id;
/* For each applicant */
foreach ($request['title'] as $key => $title) {
if (!isset($request['applicant_id'][$key])) {
$applicant_id = $this->addApplicant($request, $key, $application_id);
} else {
$applicant_id = $request['applicant_id'][$key];
$this->editApplicant($request, $key, $applicant_id);
}
/* Contact Details */
$this->addPhoneDetails($request, $key, $applicant_id);
/* Add code here for additional phones */
/* Address Details */
$this->addAddressDetails($request, $key, $applicant_id);
}
DB::commit();
return true;
} catch (\Exception $e) {
DB::rollback();
dd($e);
return false;
}
}
示例9: 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());
}
示例10: rollback
/**
* Rollback a transaction,
* so we remove all data added
* to the current test's transaction.
**/
public function rollback()
{
try {
DB::rollback();
} catch (\Exception $e) {
var_dump($e->getMessage());
}
}
示例11: bulkCreate
/**
* Bulk Lead creation
*
* @param array $data
* @param User $user
* @throws \SaleBoss\Repositories\Exceptions\RepositoryException
* @return mixed
*/
public function bulkCreate(array $data, User $user = null)
{
$data = $this->setCreatorId($data, !empty($user) ? $user->id : null);
DB::beginTransaction();
try {
$this->model->newInstance()->insert($data);
} catch (QueryException $e) {
DB::rollback();
throw new RepositoryException($e->getMessage());
}
DB::commit();
}
示例12: updateBuiltTesters
/**
* Update tester from built plan
*
* @param $planId
* @param $testersData
* @return array|bool
*/
public function updateBuiltTesters($planId, $testersData, $origData)
{
$redirect = false;
$errorMsg = '';
// Start transaction
DB::beginTransaction();
// Start testers update
try {
$query = $this->model->where('plan_id', '=', $planId)->delete();
foreach ($testersData as $tester) {
$testerId = $tester['id'];
$browsers = $tester['browsers'];
$newCount = isset($browsers) ? count(explode(',', $browsers)) : 0;
// Formerly selected browsers
$oldCount = isset($origData[$testerId]) ? count(explode(',', $origData[$testerId])) : 0;
if ($oldCount == $newCount) {
$updateStatus = 0;
} elseif ($newCount > $oldCount) {
$updateStatus = 1;
} elseif ($oldCount < $newCount || $oldCount > $newCount) {
$updateStatus = -1;
}
$tester += ['update_status' => $updateStatus, 'update_status_text' => Tools::planTesterChanges($updateStatus)];
$results[] = $tester;
// Create new or update
if (count($tester['input-ids']) > 0 && !empty($browsers)) {
$this->model->create(['plan_id' => $planId, 'user_id' => $testerId, 'browsers' => $browsers]);
}
}
} catch (\Exception $e) {
$errorMsg = $e->getMessage();
$redirect = true;
} catch (QueryException $e) {
$errorMsg = $e->getErrors();
$redirect = true;
} catch (ModelNotFoundException $e) {
$errorMsg = $e->getErrors();
$redirect = true;
}
// Redirect if errors
if ($redirect) {
// Rollback
DB::rollback();
// Log to system
Tools::log($errorMsg, $testersData);
return false;
}
// Commit all changes
DB::commit();
return $results;
}
示例13: table
public function table($options)
{
$this->onInit($options);
DB::beginTransaction();
try {
$result = $this->controller->handle();
} catch (JarboeValidationException $e) {
DB::rollback();
$data = array('status' => false, 'errors' => explode('|', $e->getMessage()));
return Response::json($data);
}
DB::commit();
$this->onFinish();
return $result;
}
示例14: addFollow
/**
* Add new follow data
*
* @param $follower_id
* @param $followed_id
* @throws \Exception
*/
public function addFollow($follower_id, $followed_id)
{
try {
DB::beginTransaction();
$this->follower_user_id = $follower_id;
$this->followed_user_id = $followed_id;
$this->date_created = date('Y-m-d H:i:s');
$this->save();
$notification_data = new Notification();
$notification_data->addNotificationNewFollower($follower_id, $followed_id);
DB::commit();
} catch (\Exception $e) {
DB::rollback();
throw $e;
}
}
示例15: assign
function assign(array $request, $application_id)
{
DB::beginTransaction();
try {
$application = Application::find($application_id);
ApplicationLender::create(['description' => $request['description'], 'lender_id' => $request['lender_id'], 'application_id' => $application_id, 'status' => 0]);
$application->submitted = 1;
$application->save();
DB::commit();
return true;
} catch (\Exception $e) {
DB::rollback();
dd($e);
return false;
}
}