本文整理汇总了PHP中app\models\Permission::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::all方法的具体用法?PHP Permission::all怎么用?PHP Permission::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Permission
的用法示例。
在下文中一共展示了Permission::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$role = Role::whereName(Role::getAdministratorName())->firstOrFail();
Permission::all()->map(function ($permission) use($role) {
$role->grant($permission);
});
}
示例2: putAll
/**
* Handle permissions change
*
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function putAll(Request $request)
{
$permissions = Permission::all();
$input = array_keys($request->input('permissions'));
try {
DB::beginTransaction();
$permissions->each(function ($permission) use($input) {
if (in_array($permission->id, $input)) {
$permission->allow = true;
} else {
$permission->allow = false;
}
$permission->save();
});
DB::commit();
flash()->success(trans('permissions.save_success'));
} catch (\Exception $e) {
var_dump($e->getMessage());
die;
flash()->error(trans('permissions.save_error'));
}
try {
Cache::tags(['permissions'])->flush();
} catch (\Exception $e) {
Cache::flush();
}
return redirect()->back();
}
示例3: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$list = Permission::all();
$list = $this->buildTree($list);
$title = '权限管理';
return view('admin.permissionList', array('title' => $title, 'list' => $list));
}
示例4: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$administrator = Role::firstOrCreate(['name' => 'administrator', 'label' => 'Administrator']);
// Welcome Permissions
Permission::firstOrCreate(['name' => 'admin.welcome.index', 'label' => 'View Administrator Welcome']);
// User Permissions
Permission::firstOrCreate(['name' => 'admin.users.index', 'label' => 'View All Users']);
Permission::firstOrCreate(['name' => 'admin.users.create', 'label' => 'Create Users']);
Permission::firstOrCreate(['name' => 'admin.users.edit', 'label' => 'Edit Users']);
Permission::firstOrCreate(['name' => 'admin.users.show', 'label' => 'View Users']);
Permission::firstOrCreate(['name' => 'admin.users.destroy', 'label' => 'Delete Users']);
// Role Permissions
Permission::firstOrCreate(['name' => 'admin.roles.index', 'label' => 'View All Roles']);
Permission::firstOrCreate(['name' => 'admin.roles.create', 'label' => 'Create Roles']);
Permission::firstOrCreate(['name' => 'admin.roles.edit', 'label' => 'Edit Roles']);
Permission::firstOrCreate(['name' => 'admin.roles.show', 'label' => 'View Roles']);
Permission::firstOrCreate(['name' => 'admin.roles.destroy', 'label' => 'Delete Roles']);
// Permission Permissions
Permission::firstOrCreate(['name' => 'admin.permissions.index', 'label' => 'View All Permissions']);
Permission::firstOrCreate(['name' => 'admin.permissions.create', 'label' => 'Create Permissions']);
Permission::firstOrCreate(['name' => 'admin.permissions.edit', 'label' => 'Edit Permissions']);
Permission::firstOrCreate(['name' => 'admin.permissions.show', 'label' => 'View Permissions']);
Permission::firstOrCreate(['name' => 'admin.permissions.destroy', 'label' => 'Delete Permissions']);
// User Permission Permissions
Permission::firstOrCreate(['name' => 'admin.users.permissions.store', 'label' => 'Add Permissions to Users']);
Permission::firstOrCreate(['name' => 'admin.users.permissions.destroy', 'label' => 'Remove Permissions from Users']);
// Role Permission Permissions
Permission::firstOrCreate(['name' => 'admin.roles.permissions.store', 'label' => 'Add Permissions to Roles']);
Permission::firstOrCreate(['name' => 'admin.roles.permissions.destroy', 'label' => 'Remove Permissions from Roles']);
// Role User Permissions
Permission::firstOrCreate(['name' => 'admin.roles.users.store', 'label' => 'Add Users to Roles']);
Permission::firstOrCreate(['name' => 'admin.roles.users.destroy', 'label' => 'Remove Users from Roles']);
$administrator->grant(Permission::all());
}
示例5: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$roles = Role::all();
$permissions = Permission::all();
$usersWithRoles = User::with('roles')->orderBy('last_name')->get();
return view('admin.roles.index', ['roles' => $roles, 'permissions' => $permissions, 'users' => $usersWithRoles]);
}
示例6: getAllPermission
public function getAllPermission($sortActions = false)
{
$permissions = $this->groupPermissionByResource(Permission::all());
if (!$sortActions) {
return $permissions;
}
return $this->sortActions($permissions);
}
示例7: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$data[$this->permissions] = Permission::all();
$data['createbtn'] = Permission::hasPermission('permissions.create');
$data['editbtn'] = Permission::hasPermission('permissions.edit');
$data['deletebtn'] = Permission::hasPermission('permissions.delete');
return view('permissions.index', $data);
}
示例8: edit
public function edit($id)
{
$role = Role::findOrFail($id);
$permissions = Permission::all();
$permission = new Permission();
$permissionRole = $permission->permissionRole($role->id);
return view('admin.role.edit', ['role' => $role, 'permissions' => $permissions, 'permissionRole' => $permissionRole]);
}
示例9: pget
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function pget($id)
{
$role = Role::where('id', '=', $id)->first();
$list = Permission::all();
$list = $this->buildTree($list);
$perms = array();
foreach ($role->perms as $row) {
$perms[] = $row->id;
}
$title = '权限设置';
return view('admin.permissionShow', array('title' => $title, 'list' => $list, 'perms' => $perms, 'id' => $id));
}
示例10: edit
/**
* @param $id
*
* @return \Illuminate\View\View
*/
public function edit($id)
{
$user = $this->user->find($id);
$page_title = trans('admin/users/general.page.edit.title');
// "Admin | User | Edit";
$page_description = trans('admin/users/general.page.edit.description', ['full_name' => $user->full_name]);
// "Editing user";
if (!$user->isEditable()) {
abort(403);
}
$roles = $this->role->all();
$perms = $this->perm->all();
// $roleCollection = \App\Models\Role::take(10)->get(['id', 'display_name'])->lists('display_name', 'id');
// $roleList = [''=>''] + $roleCollection->all();
return view('admin.users.edit', compact('user', 'roles', 'perms', 'page_title', 'page_description'));
}
示例11: getAddMenu
public function getAddMenu($parent)
{
// echo PHP_EOL, "The recognized text is:", $text, PHP_EOL;
//Log::info(Route::current()->all());
// Log::info(Route::getCurrentRoute()->getPath());
//Log::info($parent);
Session::set('cur', $parent);
$parents = DB::table('permissions')->where('parent', 0)->get();
$permission = Permission::all();
$inputRole = "<select id='col5' class='small m-wrap' tabindex='1'>";
$inputRole = $inputRole . "<option value='0'>Root</option>";
foreach ($parents as $parent) {
$inputRole = $inputRole . '<option value=' . $parent->id . '>' . $parent->display_name . '</option>';
}
$inputRole = $inputRole . "</select>";
Log::info($inputRole);
return view('user.add_menu', ['permission' => $permission, 'inputRole' => $inputRole]);
}
示例12: edit
public function edit()
{
foreach (Route::getRoutes() as $value) {
if (strpos($value->getName(), "admin.") !== false) {
try {
$displayName = ucwords(strtolower(str_replace(".", " ", str_replace("admin.", "", $value->getName()))));
$permissions = new Permission();
$permissions->name = $value->getName();
$permissions->display_name = $displayName;
$permissions->save();
} catch (\Illuminate\Database\QueryException $e) {
}
}
}
$permissions = Permission::all();
$role = Role::find(Input::get('id'));
$action = "admin.roles.save";
return view(Config('constants.adminRoleView') . '.addEdit', compact('permissions', 'role', 'action'));
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(PermissionRequest $request)
{
$arrayPermissionRoleMapping = $request->permissionRoles;
$permissions = Permission::all();
$roles = Role::all();
foreach ($permissions as $permissionkey => $permission) {
foreach ($roles as $roleKey => $role) {
//If checkbox is clicked attach the permission
if (!empty($arrayPermissionRoleMapping[$permissionkey][$roleKey])) {
// check that this permission has not already been attached to a role before attempting it again!
if (!$role->perms->find($permission->id)) {
$role->attachPermission($permission);
}
} elseif (empty($arrayPermissionRoleMapping[$permissionkey][$roleKey])) {
$role->detachPermission($permission);
}
}
}
return redirect()->to('permission.index')->with('message', trans_choice('messages.record-successfully-saved', 1))->with('active_permission', $permission->id);
}
示例14: getPermission
public function getPermission($id)
{
return Permission::all();
}
示例15: assignPermission
/**
* Gets all the current list of permission and returns to a view page.
* @param $id
* @return $this
*/
public function assignPermission($id)
{
/*$permissions = $this->role->getPermissionsForGivenRole($id);*/
$permissions = \DB::select('select permission_id from permission_role where role_id = ?', array($id));
$permissions_array = array();
foreach ($permissions as $key => $value) {
$permissions_array[] = $value->permission_id;
}
//dd($permissions_array);
$all_permissions = Permission::all();
$role = $this->role->getRoleById($id);
return view('userManagement.roles.permission')->with('all_permissions', $all_permissions)->with('role', $role)->with('permissions', $permissions_array);
}