本文整理汇总了PHP中App\Http\Controllers\DB::rollback方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::rollback方法的具体用法?PHP DB::rollback怎么用?PHP DB::rollback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Controllers\DB
的用法示例。
在下文中一共展示了DB::rollback方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destory
public function destory()
{
try {
\DB::beginTransaction();
$product = Product::find(\Request::get('product_id'));
$product->status = 'STOP';
$product->save();
\DB::commit();
} catch (exception $e) {
\DB::rollback();
return \Response::json(['result' => 'success']);
}
return \Response::json(['result' => 'success']);
}
示例2: getCheckuser
public function getCheckuser()
{
$sessionfb = Session::get('sessionfb');
dd($sessionfb);
$userfb = Session::get('userfb');
$check = User::checkuser($userfb, $nh);
//kiem tra id nha hang
//kiem tra check, neu khong co nguoi dung trong db
if ($check == false) {
if (!NhaHang::checkid($nh)) {
return Redirect::to('/error');
} else {
DB::beginTransaction();
try {
$user = User::createuser($userfb, htmlentities($_SERVER['HTTP_USER_AGENT']), $nh);
$code = Code::createcode($userfb, $type, $nh);
DB::commit();
} catch (Exception $e) {
//If there are any exceptions, rollback the transaction
DB::rollback();
}
//Everything worked perfectly. Commit the transaction
$user = $userfb->asArray();
$user['fb_id'] = $user['id'];
Session::put('user', (object) $user);
return Redirect::to('/hello');
}
} else {
$user = $check;
$user->save();
$c = false;
$arrs = Code::where('fb_id', $user->fb_id)->get();
foreach ($arrs as $arr) {
if ($nh == $arr->nhahang_id) {
$c = true;
break;
}
}
if (!$c) {
$code = Code::createcode($userfb, $type, $nh);
Session::put('user', $user);
return Redirect::to('/hello');
} else {
Session::put('user', $user);
return Redirect::to('/hello');
}
}
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Requests\AddTask $request)
{
try {
\DB::beginTransaction();
$task = new Task();
$task->fill($request->only('title', 'description', 'deadline'));
$task->user_id = auth()->user()->id;
$task->save();
\DB::commit();
flash()->success('Task added to list successfully.');
return redirect()->back();
} catch (\Exception $e) {
\DB::rollback();
flash()->error($e->getMessage());
return redirect()->back()->withInput();
}
}
示例4: product_submit
public function product_submit()
{
$data = \Request::input();
try {
\DB::beginTransaction();
$order = new Order();
$order->product_id = $data['product_id'];
$order->user_id = \Auth::user()->id;
$order->quantity = $data['item_count'];
$order->status = 'Inprogress';
$order->save();
// 견적서 메일 발송
//\Event::fire('order.send_mail', [$data]);
\DB::commit();
} catch (exception $e) {
\DB::rollback();
#return \Response::json(['result' => 'error']);
}
#return \Response::json(['result' => 'success']);
return \Redirect()->route('order_product', 1);
// 영업사원 user_id 로 변경 해야 함.
}
示例5: put
public function put(Request $request, $id)
{
//return $request->all();
if (strtolower($request->input('id')) == strtolower($id)) {
$manday = Manday::find($id);
if (count($manday) > 0) {
//\DB::beginTransaction();
$manday->custcount = $request->input('custcount');
$manday->headspend = $request->input('headspend');
$manday->empcount = $request->input('empcount');
$manday->workhrs = $request->input('workhrs');
$manday->breakhrs = $request->input('breakhrs');
$manday->loading = $request->input('loading');
\DB::beginTransaction();
//Start transaction!
try {
$manday->save();
try {
foreach ($request->input('manskeddtls') as $mandtl) {
$n = Mandtl::find($mandtl['id']);
if (count($manday) > 0) {
$n->daytype = $mandtl['daytype'];
$n->timestart = $mandtl['timestart'];
$n->breakstart = $mandtl['breakstart'];
$n->breakend = $mandtl['breakend'];
$n->timeend = $mandtl['timeend'];
$n->workhrs = $mandtl['workhrs'];
$n->breakhrs = $mandtl['breakhrs'];
$n->loading = $mandtl['loading'];
$n->save();
} else {
\DB::rollback();
return 'no mandtl found!';
}
}
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
\DB::commit();
$manday->load('manskeddtls');
return $manday;
//return $request->input('manskeddtls');
}
}
return redirect(URL::previous());
//return ['iid' => $request->input('id'), 'rid'=>$id];
}
示例6: post
public function post(Request $request)
{
//
$this->validate($request, ['date' => 'required|date|max:10', 'weekno' => 'required']);
// check weekno if exist
$mansked = Mansked::whereWeekno($request->input('weekno'))->get();
if (count($mansked) > 0) {
return redirect('/branch/mansked/add')->withErrors(['message' => 'Week ' . $request->input('weekno') . ' already created!'])->withInput();
}
//$mansked = array_shift($mansked);
$mansked = new Mansked();
//return $mansked->getRefno();
$mansked->refno = $mansked->getRefno();
$mansked->date = $request->input('date');
$mansked->weekno = $request->input('weekno');
$mansked->branchid = $request->input('branchid');
$mansked->managerid = $request->input('managerid');
$mansked->mancost = $request->input('mancost');
$mansked->notes = $request->input('notes');
$mansked->id = $mansked->get_uid();
$mandays = [];
foreach ($mansked->getDaysByWeekNo($request->input('weekno')) as $key => $date) {
$manday = new Manday();
$manday->date = $date;
$manday->id = $manday->get_uid();
array_push($mandays, $manday);
}
\DB::beginTransaction();
//Start transaction!
try {
$mansked->save();
try {
$mansked->manskeddays()->saveMany($mandays);
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
\DB::commit();
//$mansked->id
//return $id;
//return dd($mansked);
$mansked->load('manskeddays');
foreach ($mansked->manskeddays as $manskedday) {
foreach ($this->employees as $employee) {
$mandtl = new Mandtl();
$mandtl->employeeid = $employee->id;
$mandtl->id = $mandtl->get_uid();
$manskedday->manskeddtls()->save($mandtl);
}
}
return $mansked;
}
示例7: copyMansked
public function copyMansked(Request $request)
{
$this->validate($request, ['lweekno' => 'required', 'nweekno' => 'required', 'year' => 'required', 'lmanskedid' => 'required']);
$mansked1 = Mansked::whereWeekno($request->input('nweekno'))->where('year', $request->input('year'))->where('branchid', $request->user()->branchid)->get();
if (count($mansked1) > 0) {
return redirect('/task/mansked')->withErrors(['message' => 'Manpower Schedule Week ' . $request->input('nweekno') . ' already exist!'])->withInput();
}
$mansked = Mansked::find($request->input('lmanskedid'));
if (count($mansked) <= 0) {
return redirect('/task/mansked')->withErrors(['message' => 'Pointer Week ' . $request->input('lweekno') . ' not found!'])->withInput();
}
$mansked->load('manskeddays');
$mandays = $mansked->manskeddays;
foreach ($mandays as $manday) {
$manday->load('manskeddtls');
}
$new_mansked = new Mansked();
//return $mansked->getRefno();
$new_mansked->refno = $new_mansked->getRefno();
$new_mansked->date = $mansked->date->format('Y-m-d');
$new_mansked->weekno = $request->input('nweekno');
$new_mansked->year = $request->input('year');
$new_mansked->branchid = $mansked->branchid;
$new_mansked->managerid = $mansked->managerid;
$new_mansked->mancost = $mansked->mancost;
$new_mansked->notes = $mansked->notes;
$new_mansked->id = $mansked->get_uid();
\DB::beginTransaction();
//Start transaction!
$new_mandays = [];
foreach ($new_mansked->getDaysByWeekNo($request->input('nweekno'), $request->input('year')) as $key => $date) {
$new_manday = new Manday();
$new_manday->date = $date->format('Y-m-d');
$new_manday->custcount = $mandays[$key]->custcount;
$new_manday->headspend = $mandays[$key]->headspend;
$new_manday->empcount = $mandays[$key]->empcount;
$new_manday->workhrs = $mandays[$key]->workhrs;
$new_manday->breakhrs = $mandays[$key]->breakhrs;
$new_manday->overload = $mandays[$key]->overload;
$new_manday->underload = $mandays[$key]->underload;
$new_manday->id = $new_manday->get_uid();
$new_mandtls = [];
foreach ($mandays[$key]->manskeddtls as $mandtl) {
$new_mandtl = new Mandtl();
$new_mandtl->employeeid = $mandtl->employeeid;
$new_mandtl->daytype = $mandtl->daytype;
$new_mandtl->timestart = $mandtl->timestart;
$new_mandtl->breakstart = $mandtl->breakstart;
$new_mandtl->breakend = $mandtl->breakend;
$new_mandtl->timeend = $mandtl->timeend;
$new_mandtl->workhrs = $mandtl->workhrs;
$new_mandtl->breakhrs = $mandtl->breakhrs;
$new_mandtl->loading = $mandtl->loading;
$new_mandtl->id = $new_mandtl->get_uid();
array_push($new_mandtls, $new_mandtl);
}
try {
$new_manday->manskeddtls()->saveMany($new_mandtls);
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
array_push($new_mandays, $new_manday);
}
try {
$new_mansked->save();
try {
$new_mansked->manskeddays()->saveMany($new_mandays);
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
\DB::commit();
return redirect('/task/mansked')->with(['new' => true])->with('alert-success', 'Week ' . $request->input('lweekno') . ' successfully copied!');
$new_mansked->load('manskeddays');
$new_mandays = $new_mansked->manskeddays;
foreach ($new_mandays as $new_manday) {
$new_manday->load('manskeddtls');
}
return $new_mansked;
}
示例8: put
public function put(Request $request, $id)
{
//return $request->all();
if (strtolower($request->input('id')) == strtolower($id)) {
$manday = Manday::find($id);
if (count($manday) > 0) {
//\DB::beginTransaction();
$manday->custcount = $request->input('custcount');
$manday->headspend = $request->input('headspend');
$manday->empcount = $request->input('empcount');
$manday->workhrs = $request->input('workhrs');
$manday->breakhrs = $request->input('breakhrs');
$manday->overload = $request->input('overload');
$manday->underload = $request->input('underload');
\DB::beginTransaction();
//Start transaction!
try {
$manday->save();
try {
foreach ($request->input('manskeddtls') as $mandtl) {
$n = Mandtl::find($mandtl['id']);
if (count($n) > 0) {
//dd(count($n));
foreach ($mandtl as $key => $value) {
if ($mandtl['timestart'] == 'off') {
$n->breakstart = 'off';
$n->breakend = 'off';
$n->timeend = 'off';
}
$n->{$key} = $value;
}
$n->save();
} else {
//dd($mandtl);
$m = new Mandtl();
foreach ($mandtl as $key => $value) {
if ($key == 'id') {
$m->id = $m->get_uid();
} else {
$m->{$key} = $value;
}
}
$m->mandayid = $request->input('id');
$m->save();
//\DB::rollback();
//return 'no mandtl found!';
}
}
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
\DB::commit();
//$manday->load('manskeddtls');
//return $manday;
//return $request->input('manskeddtls');
}
}
return redirect('/task/manday/' . $manday->lid())->with('alert-success', 'Record saved!');
//return ['iid' => $request->input('id'), 'rid'=>$id];
}
示例9: relateVn
private function relateVn($parent_vn_id, $child_vn_id)
{
if (!empty($parent_vn_id) && !empty($child_vn_id)) {
\DB::beginTransaction();
try {
$parent_relation = VnRelation::firstOrNew(['vn_id' => $parent_vn_id]);
if (is_null($parent_relation->group_id)) {
$max_group_id = VnRelation::max('group_id') || 0;
if (!$max_group_id) {
$max_group_id++;
}
$parent_relation->group_id = $max_group_id;
}
$parent_relation->vn_id = $parent_vn_id;
$exec_parent_relation = $parent_relation->save();
$child_relation = VnRelation::firstOrNew(['vn_id' => $child_vn_id]);
if (is_null($child_relation->group_id)) {
$child_relation->group_id = $parent_relation->group_id;
}
$child_relation->vn_id = $child_vn_id;
$exec_child_relation = $child_relation->save();
} catch (\Exception $e) {
\DB::rollback();
throw $e;
}
if ($exec_parent_relation && $exec_child_relation) {
\DB::commit();
return true;
} else {
\DB::rollback();
throw new \Symfony\Component\HttpKernel\Exception\ConflictHttpException();
}
}
}
示例10: updateLinks
public function updateLinks(Request $request)
{
$updatelink = new UpdateLinkRequest();
$validator = Validator::make($request->all(), $updatelink->rules(), $updatelink->messages());
if ($validator->fails()) {
return response()->json(['success' => false, 'errors' => $validator->errors()->toArray()], 400);
}
$userID = $request->user_id;
$links = $request->links;
\DB::beginTransaction();
$link = User::find($userID)->links;
for ($i = 0; $i < count($links); $i++) {
$reflink = $link->find($links[$i]['id']);
$reflink->link = $links[$i]['link'];
$reflink->save();
try {
if (!$reflink) {
throw new \Exception('We Have Restricted You From Editing Others Link!');
}
} catch (\Exception $e) {
\DB::rollback();
$errors = ['ExceptionError' => $e->getMessage()];
return response()->json(['success' => false, 'errors' => $errors], 400);
// Failed Creation
}
}
\DB::commit();
return response()->json(['success' => true, 'message' => 'Link Have Been Renamed!'], 200);
}
示例11: postupdateig
public function postupdateig(Request $request)
{
if ($request->hasFile('file')) {
$file_path = $request->file('file')->move(storage_path() . '/uploads/temp/', $request->file('file')->getClientOriginalName());
\DB::beginTransaction();
try {
set_time_limit(0);
$reader = ReaderFactory::create(Type::XLSX);
// for XLSX files
$reader->open($file_path);
foreach ($reader->getSheetIterator() as $sheet) {
if ($sheet->getName() == 'Sheet1') {
$cnt = 0;
foreach ($sheet->getRowIterator() as $row) {
if ($cnt > 0) {
if (!empty($row[5])) {
// dd($row);
$updated_ig = UpdatedIg::where('store_code', $row[8])->where('sku_code', $row[13])->first();
if (!empty($updated_ig)) {
$updated_ig->ig = $row[23];
$updated_ig->update();
} else {
// dd($row);
UpdatedIg::firstOrCreate(['area' => $row[0], 'region_code' => $row[1], 'region' => $row[2], 'distributor_code' => $row[3], 'distributor' => $row[4], 'agency_code' => $row[5], 'agency' => $row[6], 'storeid' => $row[7], 'store_code' => $row[8], 'store_name' => $row[9], 'channel_code' => $row[10], 'channel' => $row[11], 'other_code' => $row[12], 'sku_code' => $row[13], 'description' => $row[14], 'division' => $row[15], 'category' => $row[16], 'sub_category' => $row[17], 'brand' => $row[18], 'conversion' => $row[19], 'min_stock' => $row[20], 'fso_multiplier' => $row[21], 'lpbt' => $row[22], 'ig' => $row[23]]);
}
$store = Store::where('store_code', $row[8])->first();
if (!empty($store)) {
$item = Item::where('sku_code', $row[13])->first();
if (!empty($item)) {
StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->update(['ig' => $row[23]]);
}
}
}
}
$cnt++;
}
}
}
$hash = UpdateHash::find(1);
if (empty($hash)) {
UpdateHash::create(['hash' => \Hash::make(date('Y-m-d H:i:s'))]);
} else {
$hash->hash = md5(date('Y-m-d H:i:s'));
$hash->update();
}
\DB::commit();
$reader->close();
} catch (\Exception $e) {
\DB::rollback();
dd($e);
}
if (\File::exists($file_path)) {
\File::delete($file_path);
}
Session::flash('flash_message', 'Updated IG successfully updated.');
Session::flash('flash_class', 'alert-success');
} else {
Session::flash('flash_message', 'Error updating item IG.');
Session::flash('flash_class', 'alert-danger');
}
return redirect()->route("item.updatedig");
}