本文整理匯總了PHP中app\models\Role::addOrModify方法的典型用法代碼示例。如果您正苦於以下問題:PHP Role::addOrModify方法的具體用法?PHP Role::addOrModify怎麽用?PHP Role::addOrModify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Role
的用法示例。
在下文中一共展示了Role::addOrModify方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: responseEdit
public function responseEdit($id)
{
$response = parent::responseEdit($id);
$validation = $response['validation'];
unset($response['validation']);
$role = Role::find($id);
$menus = Menu::ofParent(null)->sort()->get();
$response['role'] = $role;
$response['menus'] = $menus;
if ($response['initial'] == true) {
// Pas form baru kebuka
$response['errors'] = [];
foreach ($this->validations as $f => $v) {
$fields[$f] = $role->{$f};
if (is_a($fields[$f], 'Illuminate\\Support\\Collection')) {
$fields[$f] = $fields[$f]->toArray();
}
}
foreach ($fields['permissions'] as $f) {
$sx = explode(',', $f['privileges']);
foreach ($sx as $ff) {
$fields['permissions[' . $f['menu_id'] . '][' . strtolower($ff) . ']'] = 'on';
}
}
$response['fields'] = $fields;
// dd($fields);
$response['output'] = view('backend.pages.security.roles.form-ajax', $response)->render();
} elseif ($validation->passes()) {
// Pas validasi berhasil
$data = $this->normaliseData($response['data']);
// dd($data);
Role::addOrModify($data, $id);
$response['status'] = true;
} else {
// Pas validasi gagal
$response['fields'] = $response['data'];
$response['fields']['label'] = $role->label;
$response['output'] = view('backend.pages.security.roles.form-ajax', $response)->render();
}
return $response;
}