本文整理汇总了PHP中app\Permission类的典型用法代码示例。如果您正苦于以下问题:PHP Permission类的具体用法?PHP Permission怎么用?PHP Permission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Permission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//Roles
$userAdmin = new Role();
$userAdmin->name = 'admin';
$userAdmin->display_name = 'Administrator';
$userAdmin->description = 'User is an admin and can edit and manage users';
$userAdmin->save();
$reportsUser = new Role();
$reportsUser->name = 'reports-user';
$reportsUser->display_name = 'Reports User';
$reportsUser->description = 'Reports User can use Note Code Conflicts';
$reportsUser->save();
$csUser = new Role();
$csUser->name = 'cs-user';
$csUser->display_name = 'Customer Service User';
$csUser->description = 'Customer Service User can Upload Notes Import';
$csUser->save();
//Permissions
$userRegistration = new Permission();
$userRegistration->name = 'user-reg';
$userRegistration->display_name = 'User Registration';
$userRegistration->description = 'Create new users admin only';
$userRegistration->save();
$manageUsers = new Permission();
$manageUsers->name = 'manage-users';
$manageUsers->display_name = 'Manage Users';
$manageUsers->description = 'Manage Users - Permissions, etc.';
$manageUsers->save();
$reports = new Permission();
$reports->name = 'reports';
$reports->display_name = 'Reports Section';
$reports->description = 'Access to reports section';
$reports->save();
$admin = new Permission();
$admin->name = 'admin';
$admin->display_name = 'Admin Section';
$admin->description = 'Access to admin section';
$admin->save();
$dispositions = new Permission();
$dispositions->name = 'dispositions';
$dispositions->display_name = 'Disposition Uploads';
$dispositions->description = 'Access to Disposition Uploads';
$dispositions->save();
$notesImport = new Permission();
$notesImport->name = 'notes-import';
$notesImport->display_name = 'Upload Notes Import';
$notesImport->description = 'Access to upload notes import';
$notesImport->save();
$noteConflicts = new Permission();
$noteConflicts->name = 'note-conflicts';
$noteConflicts->display_name = 'Note Code Conflicts';
$noteConflicts->description = 'Access to Node Code Conflicts';
$noteConflicts->save();
$batchRefund = new Permission();
$batchRefund->name = 'batch-refund';
$batchRefund->display_name = 'Batch Refunds';
$batchRefund->description = 'Access to Batch Refunds';
$batchRefund->save();
}
示例2: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
/**
* Create four roles: admin, moderator, user and guest.
*/
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'Administrator';
$admin->description = 'Super User Do';
$admin->save();
$moderator = new Role();
$moderator->name = 'moderator';
$moderator->display_name = 'Moderator';
$moderator->description = 'Kan alle bestellingen zien en gebruikergegevens opvragen.';
$moderator->save();
$user = new Role();
$user->name = 'user';
$user->display_name = 'Gebruiker';
$user->description = 'Standaard gebruiker. Kan bestellingen plaatsen en eigen gegevens inkijken.';
$user->save();
$guest = new Role();
$guest->name = 'guest';
$guest->display_name = 'Gast';
$guest->description = 'Standaard gebruiker. Kan bestellingen plaatsen.';
$guest->save();
/**
* Attach roles to users.
*/
$adminUser = User::where('email', '=', 'sander@dekroon.xyz')->first();
$adminUser->attachRole($admin);
$moderatorUser = User::where('email', '=', 'john@doe.nl')->first();
$moderatorUser->attachRole($moderator);
$normalUser = User::where('email', '=', 'marie@doe.nl')->first();
$normalUser->attachRole($user);
$guestUser = User::where('email', '=', 'gast@gastman.com')->first();
$guestUser->attachRole($guest);
/**
* Create permissions.
*/
$createPage = new Permission();
$createPage->name = 'create-page';
$createPage->display_name = 'Create Pages';
$createPage->description = 'create new pages';
$createPage->save();
$editPage = new Permission();
$editPage->name = 'edit-page';
$editPage->display_name = 'Edit Pages';
$editPage->description = 'edit existing pages';
$editPage->save();
$editUser = new Permission();
$editUser->name = 'edit-user';
$editUser->display_name = 'Edit Users';
$editUser->description = 'edit existing users';
$editUser->save();
/**
* Attach permissions to roles.
*/
$admin->attachPermissions(array($createPage, $editPage, $editUser));
$moderator->attachPermissions(array($createPage, $editPage));
}
示例3: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('users')->insert(array(['id' => 1, 'name' => 'Admin', 'email' => 'admin@website.com', 'password' => Hash::make('admin'), 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 2, 'name' => 'Member', 'email' => 'member@website.com', 'password' => Hash::make('member'), 'created_at' => new DateTime(), 'updated_at' => new DateTime()]));
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'User Administrator';
$admin->description = 'User is allowed to manage and edit other users';
$admin->save();
$member = new Role();
$member->name = 'member';
$member->display_name = 'Member';
$member->description = 'User is a member';
$member->save();
$user = User::where('name', '=', 'Admin')->first();
$user->attachRole($admin);
$user = User::where('name', '=', 'Member')->first();
$user->attachRole($member);
$addLocal = new Permission();
$addLocal->name = 'add-local';
$addLocal->display_name = 'Add Local Site';
$addLocal->description = 'add new local site';
$addLocal->save();
$viewContent = new Permission();
$viewContent->name = 'view-content';
$viewContent->display_name = 'View Content';
$viewContent->description = 'view content in system';
$viewContent->save();
$admin->attachPermission($addLocal);
$admin->attachPermission($viewContent);
$member->attachPermission($viewContent);
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
// Validate the forum
$this->validate($request, ['name' => 'required|unique:forums|max:255', 'description' => 'required']);
// Create a new Forum
$forum = new Forum();
$forum->name = $request->name;
$forum->slug = str_slug($request->name, '-');
$forum->description = $request->description;
if ($forum->save()) {
// Grant the admin access to the forum
$admin = Role::find(1);
// Admin should be created when built, shouldn't be an issue
$accessForum = new Permission();
$accessForum->name = 'access-forum-' . $forum->id;
$accessForum->display_name = 'Access ' . $forum->name;
// optional
$accessForum->description = 'Ability to access and post in ' . $forum->name;
// optional
$accessForum->save();
$admin->attachPermission($accessForum);
Session::flash('alert-success', 'Forum created.');
} else {
Session::flash('alert-error', 'Could not create forum.');
}
return redirect('dashboard');
}
示例5: run
public function run()
{
$this->command->info('Roles data seeded!');
$owner = new Role();
$owner->name = 'owner';
$owner->display_name = 'Owner';
// optional
$owner->description = 'Root';
// optional
$owner->save();
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'Administrator';
// optional
$admin->description = 'Administradores';
// optional
$admin->save();
$this->command->info('Roles data attaching to users!');
if ($owner) {
$owner_user = User::where('name', '=', 'owner')->first();
// role attach alias
$owner_user->attachRole($owner);
// parameter can be an Role object, array, or id
$this->command->info('Owner role attached!');
}
if ($admin) {
$admin_user = User::where('name', '=', 'ligacbb')->first();
// role attach alias
$admin_user->attachRole($admin);
// parameter can be an Role object, array, or id
$this->command->info('Admin role attached!');
}
$this->command->info('Creating Permissions!');
$owner_permission = new Permission();
$owner_permission->name = 'owner-permission';
$owner_permission->display_name = 'Full control';
// optional
// Allow a user to...
$owner_permission->description = '';
// optional
$owner_permission->save();
$admin_permission = new Permission();
$admin_permission->name = 'admin-permission';
$admin_permission->display_name = 'Admin permission';
// optional
// Allow a user to...
$admin_permission->description = '';
// optional
$admin_permission->save();
$this->command->info('Attaching Owner Permission!');
$owner->attachPermission($owner_permission);
// equivalent to $admin->perms()->sync(array($owner_permission->id));
$this->command->info('Attaching Admin Permission!');
$admin->attachPermission($admin_permission);
// equivalent to $owner->perms()->sync(array($createPost->id, $editUser->id));
}
示例6: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$superAdmin = new Role();
$superAdmin->name = 'super admin';
$superAdmin->display_name = 'Super admin';
$superAdmin->description = 'This role holder has right to everything on the application.';
$superAdmin->save();
$authUser = new Role();
$authUser->name = 'auth user';
$authUser->display_name = 'Authenticated User';
$authUser->description = 'This is the basic role which every registered user will get by default.';
$authUser->save();
/**
* Manage Role Permissions
*/
$manageRolePermission = new Permission();
$manageRolePermission->name = 'manage-role-perm';
$manageRolePermission->display_name = 'Manage Role & Permissions';
$manageRolePermission->description = 'Manage roles and give permissions to role holders.';
$manageRolePermission->save();
$superAdmin->attachPermission($manageRolePermission);
/**
* Manage User Permission
*/
$manageUserPermission = new Permission();
$manageUserPermission->name = 'manage-users';
$manageUserPermission->display_name = 'Manage Users';
$manageUserPermission->description = 'Manage Users';
$manageUserPermission->save();
$superAdmin->attachPermission($manageUserPermission);
/**
* Manage Permission to see Activity
*/
$manageActivityViewPermission = new Permission();
$manageActivityViewPermission->name = 'view-activity';
$manageActivityViewPermission->display_name = 'View Activity';
$manageActivityViewPermission->description = 'View the different user activity in the system.';
$manageActivityViewPermission->save();
$superAdmin->attachPermission($manageActivityViewPermission);
/**
* Manage settings for application
*/
$manageSettingsPermission = new Permission();
$manageSettingsPermission->name = 'manage-settings';
$manageSettingsPermission->display_name = 'Manage Settings';
$manageSettingsPermission->description = 'Manage Settings for the application. User can change settings.';
$manageSettingsPermission->save();
$superAdmin->attachPermission($manageSettingsPermission);
$user = User::create(['name' => 'Amitav Roy', 'email' => 'reachme@amitavroy.com', 'password' => \Illuminate\Support\Facades\Hash::make('password'), 'first_name' => 'Amitav', 'last_name' => 'Roy', 'status' => 1]);
$authUser = User::create(['name' => 'Jhon Doe', 'email' => 'jhon.doe@gmail.com', 'password' => \Illuminate\Support\Facades\Hash::make('password'), 'first_name' => 'Jhon', 'last_name' => 'Doe', 'status' => 1]);
$authUser->attachRole($authUser);
$user->attachRole($superAdmin);
}
示例7: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$sudo = new Permission();
$sudo->name = 'sudo';
$sudo->display_name = 'I can do everything';
// optional
$sudo->description = 'I can do everything';
// optional
$sudo->save();
$listingBudget = new Permission();
$listingBudget->name = 'listing-budget';
$listingBudget->display_name = 'Listing Budget';
// optional
$listingBudget->description = 'Listing Budget';
// optional
$listingBudget->save();
$creatingBudget = new Permission();
$creatingBudget->name = 'creating-budget';
$creatingBudget->display_name = 'Creating Budget';
// optional
$creatingBudget->description = 'Creating Budget';
// optional
$creatingBudget->save();
$updatingBudget = new Permission();
$updatingBudget->name = 'updating-budget';
$updatingBudget->display_name = 'Updating Budget';
// optional
$updatingBudget->description = 'Updating Budget';
// optional
$updatingBudget->save();
$deletingBudget = new Permission();
$deletingBudget->name = 'deleting-budget';
$deletingBudget->display_name = 'Deleting Budget';
// optional
$deletingBudget->description = 'Deleting Budget';
// optional
$deletingBudget->save();
$makeTimeline = new Permission();
$makeTimeline->name = 'make-timeline';
$makeTimeline->display_name = 'Make Timeline';
// optional
$makeTimeline->description = 'Make Timeline';
// optional
$makeTimeline->save();
$knowingTasks = new Permission();
$knowingTasks->name = 'knowing-tasks';
$knowingTasks->display_name = 'Knowing Tasks';
// optional
$knowingTasks->description = 'Knowing Tasks';
// optional
$knowingTasks->save();
}
示例8: updatePermissionStatus
/**
* Methods
*/
public static function updatePermissionStatus($user_id, $resource, $actions)
{
$permission = Permission::where('user_id', $user_id)->where('resource', $resource)->first();
if (!$permission) {
$permissionData = array_merge(['user_id' => $user_id, 'resource' => $resource], $actions);
$permission = new Permission($permissionData);
$permission->save();
return true;
}
foreach ($actions as $action => $status) {
$permission->{$action} = $status;
}
$permission->save();
}
示例9: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
/*
* Hey you! Yes, you there! TRY and keep this docblock up to date will ya pease? O:-)
LIST OF PERMISSIONS
- manager-users
- manage-nominations - In place of "add-nominations"
- add-nominations - In place of "manage-nominations"
- access-reports
*/
/* Admin -- Approve and Create an account */
$manageUsers = new Permission();
$manageUsers->name = "manage-users";
$manageUsers->display_name = "Manage User Accounts";
$manageUsers->description = "Create, edit, and approve users";
$manageUsers->save();
$manageNominations = new Permission();
$manageNominations->name = "manage-nominations";
$manageNominations->display_name = "Manage All Nominations";
$manageNominations->description = "View, create, and edit all nominations";
$manageNominations->save();
$addNominations = new Permission();
$addNominations->name = "add-nominations";
$addNominations->display_name = "Add Nominations";
$addNominations->description = "Add nominations from school";
$addNominations->save();
$accessReports = new Permission();
$accessReports->name = "access-reports";
$accessReports->display_name = "Access Reports";
$accessReports->description = "Access reporting features";
$accessReports->save();
// PERMISSIONS BELOW ARE TBD.
/*
Volunteers -- May need updating
- View shifts
- Sign-up for shifts
*/
/* Volunteer -- View Shifts */
$viewShift = new Permission();
$viewShift->name = "view-shift";
$viewShift->display_name = "View available shifts";
$viewShift->save();
/* Volunteer - add shift */
$addShift = new Permission();
$addShift->name = "add-shift";
$addShift->display_name = "Add shift to work schedule";
$addShift->save();
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
if ($request->user()->hasPermission('admin')) {
$name = $request->input('name');
$permission = new Permission();
$permission->name = $request->input('name');
if ($permission->save()) {
return redirect('permissions')->withMessage('Permission saved successfully');
} else {
return redirect('permissions/create')->withErrors('Error during adding new permission');
}
} else {
return redirect('/home')->withErrors('You do not have sufficient permissions');
}
}
示例11: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$admin = new Role();
$admin->name = "administrator";
$admin->display_name = "Administrator";
$admin->description = "An administrator gains access to everything.";
$admin->power = 1000;
$admin->save();
$dashboardAccess = new Permission();
$dashboardAccess->name = "dashboard.access";
$dashboardAccess->display_name = "Dashboard access";
$dashboardAccess->description = "Grant's a user access to the dashboard.";
$dashboardAccess->save();
$admin->attachPermission($dashboardAccess);
}
示例12: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('permissions')->truncate();
Permission::create(['name' => 'can-create-request', 'display_name' => 'Can create request', 'description' => 'Allows the user to submit a new request']);
Permission::create(['name' => 'can-approve-request', 'display_name' => 'Can approve request', 'description' => 'User can approve submitted requests']);
Permission::create(['name' => 'can-admin', 'display_name' => 'Can Admin', 'description' => 'User can so anything']);
}
示例13: removePermission
public function removePermission($permission)
{
if (is_string($permission)) {
$permission = Permission::where('name', $permission)->first();
}
return $this->permissions()->detach($permission);
}
示例14: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
$role = Role::findOrFail($id);
$permission_role = Role::find($id)->permissions()->lists('permission_id')->toArray();
$permissions = Permission::lists('display_name', 'id');
return view('admin.roles.edit', compact('role', 'permissions', 'permission_role'));
}
示例15: run
public function run()
{
// create roles
$admin = Role::create(['name' => 'admin', 'display_name' => 'Admin', 'description' => 'performs administrative tasks', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
$cashier = Role::create(['name' => 'cashier', 'display_name' => 'Cashier', 'description' => 'performs cashier tasks', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
$user = Role::create(['name' => 'user', 'display_name' => 'Portal User', 'description' => 'performs all basic tasks like print receipt, etc...', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
// create permissions
$editUser = Permission::create(['name' => 'edit-user', 'display_name' => 'Edit Users', 'description' => 'manage users', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
$reporting = Permission::create(['name' => 'reporting', 'display_name' => 'Print Report, Print receipt', 'description' => 'manage reports', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
$editReporting = Permission::create(['name' => 'edit-reporting', 'display_name' => 'Edit Report, Edit receipt', 'description' => 'manage reports', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
$receipt = Permission::create(['name' => 'view-receipt', 'display_name' => 'View receipt, View Billings', 'description' => 'View recipent and view billings', 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]);
// assign permissions to roles
$admin->attachPermissions(array($editUser, $reporting, $receipt, $editReporting));
$cashier->attachPermissions(array($reporting, $receipt, $editReporting));
$user->attachPermissions(array($reporting, $receipt));
// attach admin user to admin role
$userAdmin = User::where('email', env('ADMIN_EMAIL'))->firstOrFail();
$userAdmin->attachRole($admin);
// assign default role to users
$users = User::all();
foreach ($users as $normalUser) {
if ($normalUser->hasRole('user')) {
continue;
}
$normalUser->attachRole($user);
}
}