Ejemplo n.º 1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $group = Group::with(array('menus' => function ($query) {
         $query->orderBy('name');
     }, 'permissions' => function ($query) {
         $query->orderBy('route');
     }))->findOrFail($id);
     $menus = Menu::orderBy('name')->get()->lists('name', 'id');
     $permissions = Permission::orderBy('route')->get()->lists('route', 'id');
     $groupMenus = $group->menus->lists('id');
     $groupPermissions = $group->permissions->lists('id');
     return View::make('sysguard::resource.group.edit', compact('group', 'menus', 'permissions', 'groupMenus', 'groupPermissions'));
 }
Ejemplo n.º 2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $menu = Menu::findOrFail($id);
     $menu->delete();
     return redirect()->route('menu.index');
 }
Ejemplo n.º 3
0
 /**
  * Test effective menu and permission.
  */
 public function testEffectiveItems()
 {
     Artisan::call('migrate');
     $user = User::create(['name' => 'Ifan Iqbal', 'email' => '*****@*****.**', 'password' => 'secret']);
     $group = Group::create(['name' => 'admin']);
     for ($i = 0; $i < 2; $i++) {
         $menu = Menu::create(['parent_id' => 0, 'name' => 'Menu ' . $i + 1, 'order' => $i + 1, 'enabled' => 1]);
         Menu::create(['parent_id' => $menu->id, 'name' => 'Child 1', 'order' => 1, 'enabled' => 1]);
         Menu::create(['parent_id' => $menu->id, 'name' => 'Child 2', 'order' => 2, 'enabled' => 1]);
     }
     for ($i = 0; $i < 4; $i++) {
         Permission::create(['route' => 'permission_' . $i + 1, 'enabled' => 1]);
     }
     $menus = Menu::get();
     $permissions = Permission::get();
     $user->groups()->attach($group);
     $group->menus()->sync($menus);
     $group->permissions()->sync($permissions);
     Auth::loginUsingId($user->id);
     $this->assertEquals(6, Sysguard::getEffectiveMenu()->count());
     $this->assertEquals(4, Sysguard::getEffectivePermission()->count());
 }