本文整理汇总了PHP中app\DB::transaction方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::transaction方法的具体用法?PHP DB::transaction怎么用?PHP DB::transaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\DB
的用法示例。
在下文中一共展示了DB::transaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addAnswer
public function addAnswer(Question $question, $answer)
{
$member = $this;
\DB::transaction(function () use($question, $member, $answer) {
$member->questions()->attach($question->id, ['value' => $answer]);
$member->answer_position = $question->position;
$member->save();
});
return $this;
}
示例2: createNew
public function createNew()
{
//create transaction method
try {
$new = DB::transaction(function () {
//define rules for the features.
$feature_rules = ['name' => 'required', 'url' => 'required', 'icon' => 'required', 'module' => 'required|unique:features'];
//get the form inputs from the POST
$inputs = Input::all();
//create new feature object, compare input with rules and after that create new entry into db
$feature = new Feature();
$feature_result = $feature->doCreate($inputs, $feature_rules);
if ($feature_result['status'] != 1) {
throw new Exception($feature_result['message']);
}
//if CRUD is selected.
if ($inputs['crud'] == '1') {
//define rules for permission
$permission_rules = ValidationRule::$permissionCreate;
// create inputs field for permission that need to be created - RestFul
$permission_inputs = array(['feature_id' => $feature_result['data']['id'], 'name' => 'create', 'descr' => 'Create Form', 'module' => $feature_result['data']['module'], 'position' => 'panel-default', 'url' => '/crm/' . $feature_result['data']['module'] . '/create', 'icon' => 'fa-plus', 'icon_bg' => 'btn-primary', 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'store', 'descr' => 'store record', 'module' => $feature_result['data']['module'], 'position' => 'form', 'url' => '/crm/' . $feature_result['data']['module'], 'icon' => null, 'icon_bg' => null, 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'show', 'descr' => 'Show Details', 'module' => $feature_result['data']['module'], 'position' => 'table', 'url' => '/crm/' . $feature_result['data']['module'] . '/[ID]', 'icon' => 'fa-file-text-o', 'icon_bg' => 'btn-success', 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'edit', 'descr' => 'Edit Details', 'module' => $feature_result['data']['module'], 'position' => 'table', 'url' => '/crm/' . $feature_result['data']['module'] . '/[ID]/edit', 'icon' => 'fa-edit', 'icon_bg' => 'btn-warning', 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'update', 'descr' => 'Update Details', 'module' => $feature_result['data']['module'], 'position' => 'form', 'url' => '/crm/' . $feature_result['data']['module'] . '/[ID]', 'icon' => null, 'icon_bg' => null, 'page' => 'index', 'prompt_type' => 'none', 'prompt_title' => null, 'prompt_content' => null], ['feature_id' => $feature_result['data']['id'], 'name' => 'destroy', 'descr' => 'Delete Record', 'module' => $feature_result['data']['module'], 'position' => 'table', 'url' => '/crm/' . $feature_result['data']['module'] . '/[ID]', 'icon' => 'fa-times', 'icon_bg' => 'btn-primary', 'page' => 'index', 'prompt_type' => 'confirm', 'prompt_title' => 'Delete', 'prompt_content' => 'Are you sure you wan to delete this record?'], ['feature_id' => $feature_result['data']['id'], 'name' => 'multi_destroy', 'descr' => 'Delete Multiple Record', 'module' => $feature_result['data']['module'], 'position' => 'panel-alert', 'url' => '/crm/' . $feature_result['data']['module'] . '/multi_destroy', 'icon' => 'fa-times', 'icon_bg' => 'btn-primary', 'page' => 'index', 'prompt_type' => 'confirm', 'prompt_title' => 'Delete', 'prompt_content' => 'Are you sure you wan to delete this record?']);
// foreach of the permission, insert into the db.
foreach ($permission_inputs as $permission_input) {
$permission = new Permission();
$permission_create = $permission->doCreate($permission_input, $permission_rules);
if ($permission_create['status'] != 1) {
throw new Exception($permission_create['message']);
}
}
}
#end if
//if everything OK return success
return Redirect::to('/crm/feature')->withMessage(Generate::message('SUCCESS', 'Success Create'));
});
#end transaction
} catch (Exception $e) {
return Redirect::to('/crm/feature')->withMessage(Generate::message('FAIL', $e->getMessage()));
}
return $new;
}
示例3: updateDocs
/**
* 資料を更新する
* @param array $params
*/
public static function updateDocs($params)
{
\DB::transaction(function () use($params) {
\DB::table('events_docs')->where('id', '=', $params['id'])->update(['doc_type' => 1, 'docs_url' => $params['docsUrl']]);
});
}
示例4: deleteStock
/**
* アンストックする
* @param $params
*/
public static function deleteStock($params)
{
\DB::transaction(function () use($params) {
\DB::table('stocks')->where('user_id', '=', $params['userId'])->where('snippet_id', '=', $params['snippetId'])->delete();
});
}