本文整理汇总了PHP中Illuminate\Database\Capsule\Manager::transaction方法的典型用法代码示例。如果您正苦于以下问题:PHP Manager::transaction方法的具体用法?PHP Manager::transaction怎么用?PHP Manager::transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Capsule\Manager
的用法示例。
在下文中一共展示了Manager::transaction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateRadius
public function updateRadius()
{
Capsule::transaction(function () {
Capsule::table('radcheck')->where('username', $this->user)->delete();
Capsule::table('radreply')->where('username', $this->user)->delete();
Capsule::table('radcheck')->insert($this->check);
Capsule::table('radreply')->insert($this->reply);
});
}
示例2: store
public function store()
{
$seven_days = 60 * 60 * 24 * 7;
$two_hours = 60 * 60 * 2;
$season = $_REQUEST['season'];
$venue_id = $_REQUEST['venue_id'];
$activity = $_REQUEST['activity'];
$lastSeasonsLeague = League::where('season', $season - 1)->where('venue_id', $venue_id)->where('activity', $activity)->first();
$lastSeasonsLastGame = Event::where('league_id', $lastSeasonsLeague->id)->where('week_num', 'Wild Card')->where('game_num', 1)->first();
$start_dt = $_REQUEST['start_dt'];
$start_dt = $start_dt ? strtotime($start_dt) : strtotime($lastSeasonsLastGame->date) + $seven_days;
$start_wk = $_REQUEST['start_wk'];
$start_wk -= 1;
$week_cnt = $_REQUEST['week_cnt'];
$game_cnt = $_REQUEST['game_cnt'];
$games_tm = $_REQUEST['games_tm'];
$games_tm = $games_tm ? strtotime($games_tm) : strtotime($lastSeasonsLastGame->time);
$events = [];
for ($i = $start_wk; $i <= $week_cnt; $i++) {
$week_num = $i == $week_cnt ? 'Wild Card' : $i + 1;
for ($j = 0; $j < $game_cnt; $j++) {
$datetime = date('Y-m-d', $start_dt + $seven_days * $i) . ' ' . date('H:i:s', $games_tm + $two_hours * $j);
$game_num = $j + 1;
$league = League::where('season', $season)->where('venue_id', $venue_id)->where('activity', $activity)->first();
if (!$league) {
$league = new League();
$league->season = $season;
$league->venue_id = $venue_id;
$league->activity = $activity;
$league->save();
}
$event = new Event();
$event->league_id = $league->id;
$event->season = $league->season;
$event->venue_id = $league->venue_id;
$event->datetime = $datetime;
$event->week_num = $week_num;
$event->game_num = $game_num;
$event->activity = $league->activity;
$events[] = $event;
}
}
try {
DB::transaction(function () use($events) {
foreach ($events as $event) {
$event->save();
}
});
$_SESSION['ALERT'] = alert('Season Added!', "Season {$season} for " . Venue::find($venue_id)->name . " was created successfully.", 'success');
} catch (Excepton $e) {
print_r($e);
exit;
$_SESSION['ALERT'] = alert('Season Not Added!', "Season {$season} for " . Venue::find($venue_id)->name . " could not be created.", 'error');
}
return redirect('/seasons');
}
示例3: migrate
public function migrate()
{
DB::transaction(function () {
$this->createCategoriesTable();
$this->createTypesTable();
$this->createDealsTable();
$this->createDealsCategoriesTable();
$this->createDealsTypesTable();
$this->createMerchantsTable();
$this->createNetworksTable();
});
}
示例4: dbTrans
/**
* Execute a database transaction
*
* @param callable $callback
* @param callable $errorCallback (optional)
* @return mixed
*/
protected function dbTrans(callable $callback, callable $errorCallback = null, array $errorContext = null)
{
try {
return DB::transaction($callback);
} catch (\Exception $e) {
Log::log(LogLevel::ERROR, $e->getMessage(), $errorContext);
if (!empty($errorCallback)) {
$errorCallback($e);
} else {
throw $e;
}
}
}
示例5: create
/**
* Index route for getting all Emojis.
*
* @param ServerRequestInterface ServerRequestInterface $request PSR-7 standard for receiving client request
* @param ResponseInterface ResponseInterface $response PSR-& standard for sending server response
*
* @return ResponseInterface HTTP response of client request
*/
public function create(ServerRequestInterface $request, ResponseInterface $response)
{
//Get Emoji data from request
$data = $request->getParsedBody();
//Extract keywords from data
$keywords = $data['keywords'];
//Decode token to get object of data
$decodedToken = Auth::decodeToken($request->getHeader('Authorization')[0], $request);
//Check if user exist with the user id
$user = User::find($decodedToken->data->uid);
//Generate emoji data to return
$emoji = ['name' => $data['name'], 'char' => $data['char'], 'category' => $data['category']];
DB::transaction(function () use($user, $emoji, $keywords) {
//Insert Emoji data into emojis table
$emoji = $user->emojis()->create($emoji);
$keywordsObj = [];
//create emoji keyword objects
foreach ($keywords as $keyword) {
$obj = new EmojiKeyword();
$obj->name = $keyword;
$keywordsObj[] = $obj;
}
//Save all keywords objects
$emoji->keywords()->saveMany($keywordsObj);
});
$response->getBody()->write(json_encode(['message' => 'Emoji created']));
return $response;
}