Ejemplo n.º 1
0
 public function addAccesss(Role $role, Menu $menu, $permission_ids = [])
 {
     $menu->roles()->attach($role->id);
     if (count($permission_ids) > 0) {
         $role->permissions()->attach($permission_ids);
     }
 }
Ejemplo n.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $user = User::create(['name' => 'Admin', 'username' => 'admin', 'password' => bcrypt('secret')]);
     $role = Role::create(['name' => 'administrator', 'display_name' => 'Administrator']);
     $user->roles()->attach($role);
     $menu = $role->addMenu('Menu', 'menu');
     $menu->addPermission('manage-menu', 'Menu Index');
     $menu->addPermission('create-menu', 'Menu Create');
     $menu->addPermission('edit-menu', 'Menu Edit');
     $menu->addPermission('delete-menu', 'Menu Delete');
     $menu = $role->addMenu('Permission', 'permission');
     $menu->addPermission('manage-permission', 'Permission Index');
     $menu->addPermission('create-permission', 'Permission Create');
     $menu->addPermission('edit-permission', 'Permission Edit');
     $menu->addPermission('delete-permission', 'Permission Delete');
     $menu = $role->addMenu('Role', 'role');
     $menu->addPermission('manage-role', 'Role Index');
     $menu->addPermission('create-role', 'Role Create');
     $menu->addPermission('edit-role', 'Role Edit');
     $menu->addPermission('delete-role', 'Role Delete');
     $menu = $role->addMenu('Workflow', 'workflow');
     $menu->addPermission('manage-workflow', 'Workflow Index');
     $menu->addPermission('create-workflow', 'Workflow Create');
     $menu->addPermission('edit-workflow', 'Workflow Edit');
     $menu->addPermission('delete-workflow', 'Workflow Delete');
     $menu->addPermission('mapping-workflow', 'Workflow Mapping');
     Model::reguard();
 }
Ejemplo n.º 3
0
 public function mapping($id, Request $request)
 {
     $workflow = Workflow::find($id);
     if ($request->isMethod('get')) {
         $workflow->load('menus');
         $title = 'Pemetaan Proses Aliran Kerja';
         $roles = Role::get()->pluck('display_name', 'id');
         $menus = Menu::get()->pluck('name', 'id');
         return view('profio/auth::workflow.mapping', compact('workflow', 'title', 'roles', 'menus'));
     } else {
         $workflow->menus()->detach();
         $workflow->permissions()->detach();
         $role_ids = $request->input('role_ids');
         $menu_ids = $request->input('menu_ids');
         DB::transaction(function () use($role_ids, $workflow, $menu_ids) {
             foreach ($role_ids as $key => $role_id) {
                 $workflow->menus()->attach($menu_ids[$key], ['role_id' => $role_id]);
                 $menu = Menu::find($menu_ids[$key]);
                 foreach ($menu->permissions as $permission) {
                     $workflow->permissions()->attach($permission->id, ['role_id' => $role_id]);
                 }
             }
             flash()->success('Pemetaan proses aliran kerja berhasil disimpan.');
         });
         return redirect()->back();
     }
 }
Ejemplo n.º 4
0
 public function edit($id)
 {
     $permission = Permission::with('roles')->find($id);
     $title = 'Edit Permission';
     $roles = Role::get()->sortBy('name');
     return view('profio/auth::permission.create', compact('permission', 'title', 'roles'));
 }
Ejemplo n.º 5
0
 public function update(Request $request, $id)
 {
     DB::transaction(function () use($request, $id) {
         $menu = Menu::find($id);
         $menu->update($request->only('name', 'url', 'icon'));
         $permission_ids = $request->input('permission_ids');
         if (!is_null($permission_ids)) {
             $menu->permissions()->sync($permission_ids);
         }
         $role = Role::findOrFail($request->get('role_id'));
         $menu->roles()->sync([$role->id]);
         flash()->success('Data Menu berhasil diperbarui.');
     });
     return redirect()->back();
 }
Ejemplo n.º 6
0
 public function manageMenu($id, Request $request)
 {
     if ($request->isMethod('get')) {
         $role = Role::findOrFail($id);
         return view('profio/auth::role.manage-menu', compact('role'));
     } else {
         $menus = $request->get('menus');
         $parents = $request->get('parents');
         for ($i = 0; $i < count($menus); $i++) {
             $menu = Menu::find($menus[$i]);
             $menu->position = $i + 1;
             $menu->parent()->associate(Menu::find($parents[$i]));
             $menu->save();
         }
         return redirect()->back();
     }
 }