本文整理汇总了PHP中Illuminate\Support\Facades\DB::rollBack方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::rollBack方法的具体用法?PHP DB::rollBack怎么用?PHP DB::rollBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\DB
的用法示例。
在下文中一共展示了DB::rollBack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public function update(Request $request, $id)
{
$departamento = $request->input('departamento');
if ($departamento != '0') {
try {
DB::beginTransaction();
$usuario = User::find($id);
$empleado = $usuario->empleado;
$empleado->nombre = Str::upper($request->input('nombre'));
$empleado->apellido_paterno = Str::upper($request->input('apellido_paterno'));
$empleado->apellido_materno = Str::upper($request->input('apellido_materno'));
$empleado->save();
$usuario->username = Str::upper($request->input('username'));
$usuario->password = bcrypt($request->input('password'));
$usuario->rol_id = $request->input('departamento');
$usuario->save();
DB::commit();
return redirect()->route('usuario.index');
} catch (QueryException $e) {
echo $e;
DB::rollBack();
return redirect()->route('usuario.edit', $id);
}
} else {
return redirect()->route('usuario.edit', $id);
}
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info("Clearing permissions... \n");
// Delete old data
$response = Action::deleteAllData();
null !== $response ? $this->error("\n" . $response . "\n") : null;
$this->info("Permissions cleared... \n");
try {
$routeData = $this->getRouteData();
$roles = Role::all();
DB::beginTransaction();
foreach ($routeData as $action => $uri) {
$action = new Action(['uri' => $uri, 'action' => $action]);
$action->save();
$this->savePermissions($roles, $action);
$this->comment("Added action " . $action->action . "\n");
}
$cache = $this->getCacheInstance(['permissions']);
$cache->flush();
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
$this->error("\n" . $e->getMessage() . "\n");
}
}
示例3: clear
public function clear(Request $request)
{
$post = $request->all();
$comment = $post['comment'];
$value = $post['amount'];
$student = $post['regNo'];
$clearedAt = $post['signedAt'];
$clearedBy = $post['signedBy'];
$comment = preg_replace('/[^A-Za-z0-9 _]/', '', $comment);
$value = preg_replace('/[^0-9]/', '', $value);
DB::beginTransaction();
$submit = DB::update("UPDATE charge\n INNER JOIN comments ON charge.students_studentNo = comments.students_studentNo\n INNER JOIN cleared_at ON charge.students_studentNo = cleared_at.students_studentNo\n INNER JOIN cleared_by ON charge.students_studentNo = cleared_by.students_studentNo\n SET\n charge.cafeteria_value = '{$value}',\n charge.queueFlag = charge.queueFlag + 1,\n comments.cafeteria = '{$comment}',\n cleared_at.cafeteria_cleared_at = '{$clearedAt}',\n cleared_by.cafeteria_cleared_by = '{$clearedBy}'\n\n WHERE charge.students_studentNo = '{$student}'\n AND comments.students_studentNo = '{$student}'\n AND cleared_at.students_studentNo = '{$student}'\n AND cleared_by.students_studentNo='{$student}' ");
if ($submit) {
DB::commit();
} else {
DB::rollBack();
}
// $admin = DB::table('departments')
// ->join('administrators','departments.administrator','=','administrators.admin_id')
// ->select('administrators.email')->where('departments.department_name','=','Library')
// ->pluck('email');
//Send Mail
// Mail::send('mails.clear', ['student' => $student ], function($message) use($admin){
// $message->to($admin)->from('strath.clearance@gmail.com', 'Strathmore University')->subject('Clearance');
// });
return redirect('/cafeteria');
}
示例4: handle
/**
* Handle the event.
*
* @param CurrencyMessageReceivedEvent
* @return void
*/
public function handle(CurrencyMessageReceivedEvent $event)
{
$timePlaced = new \DateTime($event->message->time_placed);
$rate = MonthlyRate::where('year', $timePlaced->format('Y'))->where('month', $timePlaced->format('m'))->where('currency_from', $event->message->getAttribute('currency_from'))->where('currency_to', $event->message->getAttribute('currency_to'))->get()->first();
if (is_null($rate)) {
$rate = new MonthlyRate();
$rate->tot_messages = 1;
$rate->currency_from = $event->message->getAttribute('currency_from');
$rate->currency_to = $event->message->getAttribute('currency_to');
$rate->sum_rate = $event->message->getAttribute('rate');
$rate->month = $timePlaced->format('m');
$rate->year = $timePlaced->format('Y');
} else {
$rate->tot_messages++;
$rate->sum_rate += $event->message->getAttribute('rate');
}
DB::beginTransaction();
try {
$rate->save();
$key = $rate->currency_from . '-' . $rate->currency_to;
$message = [$key => ['rate' => $rate->avg_rate, 'month' => $rate->month]];
// Push message in redis to be displayed in the frontend
$this->pushToSocket($message);
DB::commit();
} catch (\ErrorException $e) {
DB::rollBack();
// Throw the exception again to signal an error
// in the processing
throw $e;
} catch (\Exception $e) {
DB::rollBack();
throw $e;
}
}
示例5: create
/**
* Creates an activity
*
* @param null|array $data
* @return null|ActivityModel
*/
public function create($data = null)
{
DB::beginTransaction();
try {
if (is_null($data)) {
throw new NullDataException('The data array is required!');
}
foreach ($data as $k => $v) {
if (!in_array($k, $this->fields)) {
throw new CreateActivityException('Please add the correct fields!');
}
}
if (count(array_keys($data)) != count($this->fields)) {
throw new CreateActivityException('The number of given data is different than required!');
}
$this->checkFields($data);
$activity = ActivityModel::create($data);
DB::commit();
return $activity;
} catch (NullDataException $e) {
DB::rollBack();
return $e;
} catch (CreateActivityException $e) {
DB::rollBack();
return $e;
}
}
示例6: saveTrackerEntry
public function saveTrackerEntry(Request $request)
{
// return $request->all();
$validator = Validator::make($request->all(), ['desc' => 'required|min:5', 'time' => 'required|numeric', 'tags' => 'required', 'project_id' => 'required']);
if ($request->input('project_id') == 'Select Project') {
Session::flash('flash_error', 'You need to select the project');
return redirect()->back()->withInput();
}
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
try {
DB::beginTransaction();
$project = Project::with('client')->find($request->input('project_id'));
$entry = TimeEntry::create(['desc' => $request->input('desc'), 'user_id' => Auth::user()->id, 'project_id' => $project->id, 'project_name' => $project->name, 'client_name' => $project->client->name, 'time' => $request->input('time')]);
// adding the entry of the ticket with tags mapping table
foreach ($request->input('tags') as $key => $value) {
DB::table('taggables')->insert(['tag_id' => $value, 'taggable_id' => $entry->id, 'taggable_type' => 'ticket', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
}
if ($request->input('estimate_id')) {
DB::table('time_entry_estimates')->insert(['time_entry_id' => $entry->id, 'estimate_id' => $request->input('estimate_id'), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
DB::update("UPDATE estimates SET hours_consumed = hours_consumed + :hours WHERE id = :id", ['hours' => $request->input('time'), 'id' => $request->input('estimate_id')]);
}
DB::commit();
Session::flash('flash_message', 'Entry saved');
return redirect('time-tracker');
} catch (\PDOException $e) {
DB::rollBack();
abort(403, 'Data was not saved. Try again' . $e->getMessage());
}
}
示例7: create
/**
* Creates a type
*
* @param null|array $data
* @return null|TypeModel
*/
public function create($data = null)
{
DB::beginTransaction();
try {
if (is_null($data)) {
throw new NullDataException('The data array is required!');
}
foreach ($data as $k => $v) {
if (!in_array($k, $this->fields)) {
throw new CreateTypeException('Please add the correct fields!');
}
}
if (count(array_keys($data)) != count($this->fields)) {
throw new CreateTypeException('The number of given data is different than required!');
}
if (TypeModel::whereName($data['name'])->first()) {
throw new CreateTypeException('The type name already exists!');
}
$type = TypeModel::create($data);
DB::commit();
return $type;
} catch (NullDataException $e) {
DB::rollBack();
return $e;
} catch (CreateTypeException $e) {
DB::rollBack();
return $e;
}
}
示例8: uploadFile
/**
* @param Request $request
* @return array|\Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
*/
public function uploadFile(Request $request)
{
try {
try {
DB::beginTransaction();
$file = 'file';
if ($request->has('filename')) {
$file = $request->input('filename');
}
$files = $request->file($file);
if (!is_array($files)) {
$files[] = $request->file($file);
}
foreach ($files as $f) {
$extArr = explode("/", $f->getClientMimeType());
$mimeType = $f->getClientMimeType();
$fileSize = $f->getClientSize();
$originalFilename = $f->getClientOriginalName();
$type = 'local';
// check with the file extention
if ($extArr) {
$ext = $extArr[1];
}
if (!$ext) {
return false;
}
$fileName = uniqid() . "." . $ext;
if (!file_exists($this->filePath)) {
mkdir($this->filePath, 0777, true);
}
$f->move($this->filePath, $fileName);
$filePath = $this->filePath . $fileName;
// if the designation is s3. Upload
if ($request->input('destination') == 's3') {
$uploadPath = $request->input('path') . '/' . $fileName;
$type = 's3';
$s3 = Storage::disk('s3');
$s3->put($uploadPath, file_get_contents($filePath), 'public');
unlink($filePath);
$filePath = $this->s3Prefix . $uploadPath;
}
$file = File::create(['file_name' => $fileName, 'mime_type' => $mimeType, 'file_size' => $fileSize, 'file_path' => $filePath, 'client_file_name' => $originalFilename, 'type' => $type]);
$responseArr[] = $file;
}
DB::commit();
return $responseArr;
} catch (FileException $e) {
return response($e->getMessage(), 500);
}
} catch (Exception $e) {
DB::rollBack();
return response('There were some errors uploading files', 500);
}
}
示例9: handle
/**
* Run the request filter.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
DB::beginTransaction();
try {
$response = $next($request);
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
DB::commit();
EventStore::publishQueue();
return $response;
}
示例10: deleteAllData
/**
* Delete all data in the table
*/
public static function deleteAllData()
{
self::all()->each(function ($action) {
try {
DB::beginTransaction();
$action->delete();
DB::commit();
return;
} catch (Exception $e) {
DB::rollBack();
return $e->getMessage();
}
});
}
示例11: deleteAlbum
public function deleteAlbum($id)
{
DB::beginTransaction();
try {
$albumImageTable = new AlbumImage();
$albumImageTable->deleteAlbumImages($id);
$this->where("id", "=", $id)->delete();
DB::commit();
return 1;
} catch (Exception $e) {
print_r($e);
DB::rollBack();
return 0;
}
}
示例12: handleRegister
/**
* Register a user
*
* @param Registration $request
*
* @return mixed
*/
public function handleRegister(Registration $request)
{
DB::beginTransaction();
try {
$user = User::create($request->all());
$user->assignRole(config('users.default'));
auth()->login($user);
event(new UserRegistered(auth()->user()));
} catch (\Exception $exception) {
DB::rollBack();
return redirect(route('auth.register'))->with('errors', $exception->getMessage());
}
DB::commit();
return redirect(route('home'))->with('message', 'Your account has been created.');
}
示例13: store
public function store(Request $request, $id)
{
$compra = Compra::find($id);
$saldo = [];
foreach ($compra->compra_itens as $key => $it) {
if ($it->quantidade > $request->item[$key]['quantidade']) {
$saldo[$key]['produto_id'] = $it->produto_id;
$saldo[$key]['preco_compra'] = $it->preco_compra;
$saldo[$key]['quantidade'] = $it->quantidade - $request->item[$key]['quantidade'];
}
}
$new_compra = new Compra();
if (count($saldo) > 0) {
$new_compra->fornecedor_id = $compra->fornecedor_id;
$new_compra->user_id = Auth::user()->id;
$new_compra->data_compra = date('d/m/Y');
$new_compra->save();
foreach ($saldo as $s) {
$it = new CompraItem();
$it->compra_id = $new_compra->id;
$it->produto_id = $s['produto_id'];
$it->quantidade = $s['quantidade'];
$it->save();
}
}
DB::beginTransaction();
try {
foreach ($request->item as $item) {
$p = Produto::find($item['produto_id']);
$p->estoque += $item['quantidade'];
$p->save();
}
$compra->status = 2;
$compra->save();
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
throw $e;
}
if ($this->reenviaEmail($new_compra)) {
flash()->success('Confirmação de compra efetuada com sucesso e e-mail com itens que faltaram reenviado para o fornecedor');
} else {
flash()->success('Confirmação de compra efetuada com sucesso, mas email não foi enviado, envie o mesmo manualmente.');
}
return redirect()->route('compras.index');
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
// DB::transaction(function(){
try {
DB::beginTransaction();
$comprobante_compra = $request->get('comprobante_compra');
$comprobante_servicio = $request->get('comprobante_servicio');
// dd($comprobante_servicio);
foreach ($comprobante_compra as $key1 => $value1) {
$asociar = new AsociarComprobante();
$asociar->id_comprobanteVenta = $value1['id_comprobanteVenta'];
$asociar->id_comprobanteCompra = $value1['id_comprobanteCompra'];
$asociar->id_producto = $value1['id_producto'];
$asociar->precio_compra = $value1['precio_compra'];
$asociar->cantidad_compra = $value1['cantidad_compra'];
$asociar->precio_venta = $value1['precio_venta'];
$asociar->cantidad_venta = $value1['cantidad_venta'];
$asociar->save();
$id_cabecera = $asociar->id;
$compra = ComprobanteDetalleCompra::find($value1['id_comprobanteDetalleCompra']);
$compra->indicador_asociado = 'false';
$compra->save();
foreach ($comprobante_servicio as $key2 => $value2) {
if ($value1['id_producto'] == $value2['id_producto']) {
$AsociarComprobante = AsociarComprobante::find($id_cabecera);
$AsociarComprobante->id_comprobanteServicio = $value2['id_comprobanteServicio'];
$AsociarComprobante->precio_servicio = $value2['precio_servicio'];
$AsociarComprobante->cantidad_servicio = $value2['cantidad_servicio'];
$AsociarComprobante->save();
$servicio = ComprobanteDetalleServicio::find($value2['id_comprobanteDetalleServicio']);
$servicio->indicador_asociado = 'false';
$servicio->save();
}
}
}
DB::commit();
return \Response::json(array('datos' => 'correcto'));
} catch (Exception $e) {
DB::rollBack();
}
}
示例15: store
public function store(Request $request)
{
$destino = $request->input('destino');
$ruta_id = $request->input('ruta');
if ($ruta_id > 0) {
try {
DB::beginTransaction();
$nuevodestino = new Destino();
$nuevodestino->destino = $destino;
$nuevodestino->ruta_id = $ruta_id;
$nuevodestino->save();
DB::commit();
return redirect()->route('destino.index');
} catch (QueryException $ex) {
DB::rollBack();
return redirect()->route('destino.create');
}
} else {
return redirect()->route('destino.create');
}
}