本文整理汇总了PHP中App\Http\Controllers\DB::rollBack方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::rollBack方法的具体用法?PHP DB::rollBack怎么用?PHP DB::rollBack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Controllers\DB
的用法示例。
在下文中一共展示了DB::rollBack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, ['region' => 'required|max:100|unique_with:regions, region_code = region_code', 'region_code' => 'required|not_in:0']);
\DB::beginTransaction();
try {
$region = new Region();
$region->region_code = $request->region_code;
$region->region = $request->region;
$region->save();
\DB::commit();
Session::flash('flash_message', 'Region successfully added!');
return redirect()->route("region.index");
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, ['brand' => 'required|max:100|unique_with:secondary_displays, category = category_id', 'category' => 'required|not_in:0']);
\DB::beginTransaction();
try {
$display = new SecondaryDisplay();
$display->category_id = $request->category;
$display->brand = $request->brand;
$display->save();
\DB::commit();
Session::flash('flash_message', 'Secondary Display successfully added!');
return redirect()->route("secondarydisplay.index");
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, ['distributor' => 'required|max:100|unique_with:distributors, distributor_code = distributor_code', 'distributor_code' => 'required|not_in:0']);
\DB::beginTransaction();
try {
$distributor = new Distributor();
$distributor->distributor_code = $request->distributor_code;
$distributor->distributor = $request->distributor;
$distributor->save();
\DB::commit();
Session::flash('flash_message', 'Distributor successfully added!');
return redirect()->route("distributor.index");
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, ['area' => 'required|max:100|unique_with:areas, customer = customer_id', 'customer' => 'required|not_in:0']);
\DB::beginTransaction();
try {
$area = new Area();
$area->customer_id = $request->customer;
$area->area = $request->area;
$area->save();
\DB::commit();
Session::flash('flash_message', 'Area successfully added!');
return redirect()->route("area.index");
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, ['name' => 'required|max:100']);
\DB::beginTransaction();
try {
$role = new Role();
$role->name = $request->name;
$role->display_name = $request->display_name;
$role->description = $request->description;
$role->save();
\DB::commit();
Session::flash('flash_message', 'Role successfully added!');
return redirect()->route("role.index");
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例6: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, ['customer' => 'required|max:100|unique_with:customers, customer_code = customer_code, account = account_id', 'customer_code' => 'required|not_in:0', 'account' => 'required|not_in:0']);
\DB::beginTransaction();
try {
$customer = new Customer();
$customer->account_id = $request->account;
$customer->customer_code = $request->customer_code;
$customer->customer = $request->customer;
$customer->save();
\DB::commit();
Session::flash('flash_message', 'Customer successfully added!');
return redirect()->route("customer.index");
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例7: restoreStockForProduct
public function restoreStockForProduct(Request $request)
{
$purchaseOrderId = $request->input('purchase_order_id');
$productId = $request->input('product_id');
try {
\DB::beginTransaction();
// First restore the stock levels for the product deleted from the PO
$this->workOrderSchedulerService->restoreStockForProducts($purchaseOrderId, $productId);
// Now delete any workorders for this product generated by the PO
$this->workOrderSchedulerService->deleteWorkOrdersForPo($purchaseOrderId, $productId);
// Finally delete the actual purchaseOrderProduct row
$this->workOrderSchedulerService->deletePurchaseOrderProduct($purchaseOrderId, $productId);
\DB::commit();
} catch (\Exception $ex) {
\DB::rollBack();
throw $ex;
}
}
示例8: 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)
{
$user = User::findorFail($id);
$this->validate($request, ['name' => 'required|max:100', 'email' => 'required|max:100|email', 'username' => 'required|max:100']);
\DB::beginTransaction();
try {
$user->name = strtoupper($request->name);
$user->email = strtolower($request->email);
$user->username = $request->username;
$user->active = $request->active ? 1 : 0;
$user->update();
\DB::commit();
Session::flash('flash_message', 'User successfully updated!');
return redirect()->route("user.edit", [$id]);
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例9: store
public function store(Request $request)
{
$this->validate($request, ['app_name' => 'required|max:100']);
\DB::beginTransaction();
try {
$settings = Setting::find(1);
if (!empty($settings)) {
$settings->app_name = $request->app_name;
$settings->update();
} else {
$settings = new Setting();
$settings->app_name = $request->app_name;
$settings->save();
}
\DB::commit();
Session::flash('flash_message', 'Settings successfully updated!');
return redirect()->back();
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例10: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$group = FormGroup::findOrFail($id);
$this->validate($request, ['group_desc' => 'required||max:100|unique_with:form_groups,' . $id]);
\DB::beginTransaction();
try {
$group->group_desc = strtoupper($request->group_desc);
$group->secondary_display = $request->secondary_display ? 1 : 0;
$group->osa = $request->osa ? 1 : 0;
$group->sos = $request->sos ? 1 : 0;
$group->custom = $request->custom ? 1 : 0;
$group->perfect_store = $request->perfect_store ? 1 : 0;
$group->update();
\DB::commit();
Session::flash('flash_message', 'Form Group successfully updated!');
return redirect()->route("formgroup.edit", [$id]);
} catch (Exception $e) {
DB::rollBack();
return redirect()->back();
}
}
示例11: syncWithJira
public function syncWithJira($id = NULL)
{
try {
\DB::beginTransaction();
if ($id != NULL) {
Project::findOrFail($id)->syncWithJira();
} else {
foreach (Project::all() as $project) {
$project->syncWithJira();
}
}
\DB::commit();
} catch (\Exception $e) {
\DB::rollBack();
throw $e;
}
return 'synced succesfully';
}
示例12: storeform
//.........这里部分代码省略.........
$form_type = FormType::find($request->formtype);
$prompt = $request->prompt;
foreach ($request->category as $cat_id) {
$category = FormCategory::find($cat_id);
$cat_order = 1;
$a_cat_id = 0;
$clast_cnt = AuditTemplateCategory::getLastOrder($template->id);
if (empty($clast_cnt)) {
$a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]);
$a_cat_id = $a_cat->id;
} else {
$cat = AuditTemplateCategory::categoryExist($template->id, $category->id);
if (empty($cat)) {
$cat_order = $clast_cnt->category_order + 1;
$a_cat = AuditTemplateCategory::create(['category_order' => $cat_order, 'audit_template_id' => $template->id, 'category_id' => $category->id]);
$a_cat_id = $a_cat->id;
} else {
$a_cat_id = $cat->id;
}
}
foreach ($request->group as $grp_id) {
$group = FormGroup::find($grp_id);
$grp_order = 1;
$a_grp_id = 0;
$glast_cnt = AuditTemplateGroup::getLastOrder($a_cat_id);
if (empty($glast_cnt)) {
$a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]);
$a_grp_id = $a_grp->id;
} else {
$grp = AuditTemplateGroup::categoryExist($a_cat_id, $group->id);
if (empty($grp)) {
$grp_order = $glast_cnt->group_order + 1;
$a_grp = AuditTemplateGroup::create(['group_order' => $grp_order, 'audit_template_category_id' => $a_cat_id, 'form_group_id' => $group->id]);
$a_grp_id = $a_grp->id;
} else {
$a_grp_id = $grp->id;
}
}
$form = Form::create(array('audit_template_id' => $template->id, 'form_type_id' => $form_type->id, 'prompt' => strtoupper($prompt), 'required' => $request->required == '1' ? 1 : 0, 'expected_answer' => $request->expected_answer == '1' ? 1 : 0, 'exempt' => $request->exempt == '1' ? 1 : 0));
if ($request->formtype == 9) {
$multiData = array();
foreach ($request->multiselect as $option) {
$multiData[] = array('form_id' => $form->id, 'multi_select_id' => $option);
}
if (count($multiData) > 0) {
FormMultiSelect::insert($multiData);
}
}
if ($request->formtype == 10) {
$singleData = array();
foreach ($request->singleselect as $option) {
$singleData[] = array('form_id' => $form->id, 'single_select_id' => $option);
}
if (count($singleData) > 0) {
FormSingleSelect::insert($singleData);
}
}
if ($request->formtype == 11) {
if ($request->has('formula')) {
$text = $request->formula;
preg_match_all('/:(.*?):/', $text, $matches);
$index = array();
foreach ($matches[1] as $value) {
$split_up = explode('_', $value);
$last_item = $split_up[count($split_up) - 1];
$index[] = $last_item;
}
$formula1 = $text;
foreach ($matches[1] as $key => $a) {
$formula1 = str_replace(':' . $a . ':', $index[$key], $formula1);
}
$formformula = new FormFormula();
$formformula->form_id = $form->id;
$formformula->formula = $formula1;
$formformula->formula_desc = $request->formula;
$formformula->save();
}
}
if ($request->formtype == 12) {
if ($request->has('condition')) {
}
}
$order = 1;
$a_frm_id = 0;
$last_cnt = AuditTemplateForm::getLastOrder($a_grp_id);
if (!empty($last_cnt)) {
$order = $last_cnt->order + 1;
}
AuditTemplateForm::insert(array('audit_template_group_id' => $a_grp_id, 'order' => $order, 'audit_template_id' => $template->id, 'form_id' => $form->id));
}
}
\DB::commit();
Session::flash('flash_message', 'Template successfully added!');
return redirect()->route("audittemplate.form", $id);
} catch (Exception $e) {
DB::rollBack();
Session::flash('flash_message', 'An error occured in adding form!');
return redirect()->back();
}
}
示例13: import
public function import(Request $request)
{
try {
$file = $_FILES['file'];
$regexFilename = '/pacote\\d{10}.txt/';
if (preg_match($regexFilename, $file['name'])) {
$arrayObj = $this->getArrayFromFile($file['tmp_name']);
return response()->json($arrayObj, 200);
} else {
throw new \Exception('O nome do arquivo é inválido. Ex: pacote2012207180.txt', 500);
}
} catch (\Exception $e) {
\DB::rollBack();
return response()->json(['message' => $e->getMessage()], 500);
}
// $file = $request->file('file');
// $regexFilename = '/pacote\d{10}.txt/';
//
// if (preg_match($regexFilename, $file->getClientOriginalName())) {
// //dd('success');
// } else {
// //dd("Nome do arquivo precisa obedecer ao padrão deste exemplo: 'pacote9999999999.txt'");
// }
//
// $lines = explode(PHP_EOL, File::get($file->getRealPath()));
//
// $return = [];
// foreach($lines as $line) {
// $fields = explode(',', $line);
// $newArray['package_id'] = $fields[0];
// $newArray['source'] = $fields[1];
// $newArray['destination'] = $fields[2];
// $newArray['port'] = $fields[3];
// $newArray['protocol'] = $fields[4];
// $newArray['data'] = $fields[5];
// $return[] = $newArray;
// }
//
// dd($return);
}
示例14: 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)
{
$lookup = SosLookup::findOrFail($id);
$messages = ['unique_with' => 'This combination of selection already exists.'];
$this->validate($request, ['customer_id' => 'required|unique_with:sos_lookups, regions = region_id, distributors = distributor_id, stores = store_id, templates = template_id,' . $id, 'regions' => 'required', 'distributors' => 'required', 'stores' => 'required', 'templates' => 'required'], $messages);
\DB::beginTransaction();
try {
$lookup->customer_id = $request->customer_id;
$lookup->region_id = $request->regions;
$lookup->distributor_id = $request->distributors;
$lookup->store_id = $request->stores;
$lookup->template_id = $request->templates;
$lookup->update();
SosLookupPercentage::where('sos_lookup_id', $lookup->id)->delete();
foreach ($request->category as $category_id => $category) {
$less = $category[0];
foreach ($category as $key => $value) {
if ($key > 0) {
if (!empty($value)) {
$newlookup = new SosLookupPercentage();
$newlookup->sos_lookup_id = $lookup->id;
$newlookup->category_id = $category_id;
$newlookup->sos_id = $key;
$newlookup->less = $less;
$newlookup->value = $value;
$newlookup->save();
}
}
}
}
\DB::commit();
Session::flash('flash_message', 'SOS Lookup successfully updated!');
return redirect()->route("soslookup.edit", [$id]);
} catch (Exception $e) {
dd($e);
DB::rollBack();
return redirect()->back();
}
}
示例15: 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)
{
$lookup = OsaLookup::findOrFail($id);
$messages = ['unique_with' => 'This combination of selection already exists.'];
$this->validate($request, ['customer_id' => 'required|unique_with:osa_lookups, regions = region_id, distributors = distributor_id, store_id = store_id, templates = template_id,' . $id, 'regions' => 'required', 'distributors' => 'required', 'store_id' => 'required', 'templates' => 'required'], $messages);
\DB::beginTransaction();
try {
$lookup->customer_id = $request->customer_id;
$lookup->region_id = $request->regions;
$lookup->distributor_id = $request->distributors;
$lookup->store_id = $request->stores;
$lookup->template_id = $request->templates;
$lookup->update();
OsaLookupTarget::where('osa_lookup_id', $lookup->id)->delete();
foreach ($request->target as $category_id => $value) {
if ($category_id > 0) {
if (!empty($value)) {
$newlookup = new OsaLookupTarget();
$newlookup->osa_lookup_id = $lookup->id;
$newlookup->category_id = $category_id;
$newlookup->target = $value;
$newlookup->total = $request->total[$category_id];
$newlookup->save();
}
}
}
\DB::commit();
Session::flash('flash_message', 'OSA Lookup successfully updated!');
return redirect()->route("osalookup.edit", [$id]);
} catch (Exception $e) {
dd($e);
DB::rollBack();
return redirect()->back();
}
}