本文整理汇总了PHP中Permission::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP Permission::truncate方法的具体用法?PHP Permission::truncate怎么用?PHP Permission::truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Permission
的用法示例。
在下文中一共展示了Permission::truncate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$faker = Faker::create();
Permission::truncate();
DB::table('permission_role')->truncate();
Permission::create(['action' => 'User.create']);
Permission::create(['action' => 'User.view']);
Permission::create(['action' => 'User.update']);
Permission::create(['action' => 'User.delete']);
Permission::create(['action' => 'Category.create']);
Permission::create(['action' => 'Category.view']);
Permission::create(['action' => 'Category.update']);
Permission::create(['action' => 'Category.delete']);
Permission::create(['action' => 'Post.create']);
Permission::create(['action' => 'Post.view']);
Permission::create(['action' => 'Post.update']);
Permission::create(['action' => 'Post.delete']);
Permission::create(['action' => 'Comment.create']);
Permission::create(['action' => 'Comment.view']);
Permission::create(['action' => 'Comment.update']);
Permission::create(['action' => 'Comment.delete']);
Permission::create(['action' => 'Role.create']);
Permission::create(['action' => 'Role.view']);
Permission::create(['action' => 'Role.update']);
Permission::create(['action' => 'Role.delete']);
Permission::create(['action' => 'Permission.create']);
Permission::create(['action' => 'Permission.view']);
Permission::create(['action' => 'Permission.update']);
Permission::create(['action' => 'Permission.delete']);
$admin = Role::find(1);
$admin->permissions()->sync(range(1, 24));
}
示例2: run
public function run()
{
/**
* Truncate Tables
*/
Permission::truncate();
Role::truncate();
User::truncate();
DB::table('assigned_roles')->truncate();
DB::table('permission_role')->truncate();
/**
* Seed Datas
*/
$permissions = [['name' => 'Role:list', 'display_name' => 'List Roles', 'group_name' => 'Role'], ['name' => 'Role:show', 'display_name' => 'Show Role', 'group_name' => 'Role'], ['name' => 'Role:create', 'display_name' => 'Create New Role', 'group_name' => 'Role'], ['name' => 'Role:edit', 'display_name' => 'Edit Existing Role', 'group_name' => 'Role'], ['name' => 'Role:delete', 'display_name' => 'Delete Existing Role', 'group_name' => 'Role'], ['name' => 'Permission:list', 'display_name' => 'List Permissions', 'group_name' => 'Permission'], ['name' => 'Permission:show', 'display_name' => 'Show Permission', 'group_name' => 'Permission'], ['name' => 'Permission:create', 'display_name' => 'Create New Permission', 'group_name' => 'Permission'], ['name' => 'Permission:edit', 'display_name' => 'Edit Existing Permission', 'group_name' => 'Permission'], ['name' => 'Permission:delete', 'display_name' => 'Delete Existing Permission', 'group_name' => 'Permission'], ['name' => 'User:list', 'display_name' => 'List Users', 'group_name' => 'Users'], ['name' => 'User:show', 'display_name' => 'Show User', 'group_name' => 'Users'], ['name' => 'User:create', 'display_name' => 'Create New User', 'group_name' => 'Users'], ['name' => 'User:edit', 'display_name' => 'Edit Existing User', 'group_name' => 'Users'], ['name' => 'User:delete', 'display_name' => 'Delete Existing User', 'group_name' => 'Users'], ['name' => 'User:set_confirmation', 'display_name' => 'Set Existing User\'s Confirmed Status', 'group_name' => 'Users'], ['name' => 'User:set_password', 'display_name' => 'Set Existing User\'s Password', 'group_name' => 'Users']];
$roles = [['name' => 'Admin'], ['name' => 'Role Admin'], ['name' => 'Permission Admin'], ['name' => 'User Admin'], ['name' => 'User'], ['name' => 'Upload Admin']];
$users = [['first_name' => 'System', 'last_name' => 'Administrator', 'username' => 'admin', 'email' => 'admin@example.com', 'password' => 'admin', 'password_confirmation' => 'admin', 'confirmed' => 1], ['first_name' => 'System', 'last_name' => 'User', 'username' => 'user', 'email' => 'user@example.com', 'password' => 'user', 'password_confirmation' => 'user', 'confirmed' => 1]];
$user_roles = [1 => [1], 2 => [6]];
/**
* Insert Into DB
*/
foreach ($permissions as $data) {
Permission::create($data);
}
foreach ($roles as $data) {
Role::create($data);
}
foreach ($users as $data) {
$user = User::create($data);
if (isset($user_roles[$user->id])) {
$user->roles()->sync($user_roles[$user->id]);
}
}
}
示例3: postSavePermissions
public function postSavePermissions(Request $request)
{
//return $request->all();
$permissions = $request->get('permissions');
Permission::truncate();
foreach ($permissions as $role => $perms) {
foreach ($perms as $perm) {
$permission = new Permission();
$permission->roles_id = Role::where('name', $role)->first()->id;
$permission->route = $perm;
$permission->save();
}
}
return back();
}