本文整理汇总了PHP中app\models\Permission::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::findOrFail方法的具体用法?PHP Permission::findOrFail怎么用?PHP Permission::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Permission
的用法示例。
在下文中一共展示了Permission::findOrFail方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destroy
/**
* Removes the specified permission from the specified role.
*
* @param int|string $permissionId
* @param int|string $roleId
*
* @return int
*/
public function destroy($permissionId, $roleId)
{
$this->authorize('admin.roles.permissions.destroy');
$permission = $this->permission->findOrFail($permissionId);
$role = $permission->roles()->findOrFail($roleId);
return $permission->roles()->detach($role);
}
示例2: destroy
/**
* Removes the specified permission from the specified user.
*
* @param int|string $permissionId
* @param int|string $userId
*
* @return int
*/
public function destroy($permissionId, $userId)
{
$this->authorize('admin.users.permissions.destroy');
$permission = $this->permission->findOrFail($permissionId);
$user = $permission->users()->findOrFail($userId);
return $permission->users()->detach($user);
}
示例3: destroy
/**
* Removes the specified permission from the specified user.
*
* @param int|string $permissionId
* @param int|string $userId
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($permissionId, $userId)
{
$this->authorize('admin.users.permissions.destroy');
$permission = $this->permission->findOrFail($permissionId);
$user = $permission->users()->findOrFail($userId);
if ($permission->users()->detach($user)) {
flash()->success('Success!', 'Successfully removed user.');
return redirect()->route('admin.permissions.show', [$permissionId]);
}
flash()->error('Error!', 'There was an issue removing this user. Please try again.');
return redirect()->route('admin.permissions.show', [$permissionId]);
}
示例4: updatePermission
public function updatePermission($request)
{
$id = $request->route('permission');
$model = Permission::findOrFail($id);
$model->fill(['name' => $request->name, 'label' => $request->label]);
return $model->save();
}
示例5: storePermission
public function storePermission(Request $request, $id)
{
$role = Role::find($id);
$permission = Permission::findOrFail($request->all()['permission_id']);
$role->addPermission($permission);
return redirect()->back();
}
示例6: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$permission = \App\Models\Permission::findOrFail($id);
$this->authorize('destroy', $permission);
$permission->delete();
return redirect(route('permission.index'));
}
示例7: destroy
/**
* Deletes the specified permission.
*
* @param int|string $id
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($id)
{
$this->authorize('admin.permissions.destroy');
$permission = $this->permission->findOrFail($id);
if ($permission->delete()) {
flash()->success('Success!', 'Successfully deleted permission.');
return redirect()->route('admin.permissions.index');
}
flash()->error('Error!', 'There was an error deleting this permission. Please try again.');
return redirect()->route('admin.permissions.create');
}
示例8: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$data = $request->all();
$validator = Validator::make($data, ['name' => 'max:255', 'display_name' => 'max:255']);
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
$permission = Permission::findOrFail($id);
$permission->update($data);
$msg = array('msg' => '已成功更新');
return json_encode($msg);
}
示例9: store
/**
* Store permission
*
* @param array $permissionData
* @throws NotFoundException, ValidationException
* @return \App\Models\PermissionModel
*/
public function store($permissionData)
{
try {
if (array_get($permissionData, 'id')) {
$permission = PermissionModel::findOrFail((int) array_get($permissionData, 'id'))->fill($permissionData);
} else {
$permission = new PermissionModel();
$permission->fill($permissionData);
}
} catch (Exception $e) {
throw new NotFoundException(trans('app.notFound'));
}
if (!$permission->validate()) {
throw new ValidationException(trans('app.correctErrors'), $permission->errors()->toArray());
}
try {
$permission->save();
} catch (Exception $e) {
throw $e;
}
return $permission;
}
示例10: destroy
/**
* Deletes the specified permission.
*
* @param int|string $id
*
* @return bool
*/
public function destroy($id)
{
$this->authorize('admin.permissions.destroy');
$permission = $this->permission->findOrFail($id);
return $permission->delete();
}
示例11: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$permission = Permission::findOrFail($id);
$permission->delete();
Session::flash($this->success, Lang::get('ruban.permission.deleted'));
return Redirect::route('ruban.permissions.index');
}
示例12: deletePermissionsDestroy
public function deletePermissionsDestroy($id, $permissionid)
{
$role = Role::findOrFail($id);
$permission = Permission::findOrFail($permissionid);
if ($role->name == 'administrator') {
return response()->json(['status' => 'failed', 'message' => trans('api.resource_delete_failed_relationship', ['relationship' => trans('global.permission')]), 'errors' => ['name' => [trans('global.role_admin_update_error')]]])->setStatusCode(422);
}
if (!$role->hasPermission($permission->name)) {
abort(404);
}
$role->permissions()->detach($permission->id);
return response()->json(['status' => 'success', 'message' => trans('api.resource_deleted', ['resource' => trans('global.permission')])])->setStatusCode(200);
}
示例13: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$permission = Permission::findOrFail($id);
$permission->delete();
return Redirect::to('admin/permissions');
}
示例14: editPermissions
public function editPermissions(Request $request)
{
$action = $request->input('action');
if ($action == 'ADD') {
$permission = new Permission();
if ($request->input('permissionid') != '') {
$permission = Permission::find($request->input('permissionid'));
}
$permission->name = $request->input('permissionname');
$permission->display_name = $request->input('permissiondisplay');
$permission->description = $request->input('permissiondesc');
$permission->save();
} elseif ($action == 'DELETE') {
$permissionId = $request->input('permissionid');
$permission = Permission::findOrFail($permissionId);
$permission->delete();
}
return redirect('admin/permissions');
}