@endforeach
             </select>
         </div>
         <div class="col-md-6">
             @foreach(\Hamedmehryar\Laracancan\Models\Resource::all() as $resource)
                 <select name="{{$resource->id}}_resourcepermissions[]" multiple style="width: 100%; display: none" size="20" id="resourcepermissions_{{$resource->id}}" class="resource-selects">
                     <?php 
$roleResourcePermissions = $role->resourcePermissions;
$roleResourcePermissionsIds = array();
foreach ($roleResourcePermissions as $p) {
    $roleResourcePermissionsIds[] = $p->id;
}
?>
                     @foreach($resource->resourcePermissions as $permission)
                         <?php 
$resourcePermission = \Hamedmehryar\Laracancan\Models\Resourcepermission::where('permission_id', $permission->id)->where('resource_id', $resource->id)->where('parent_id', null)->first();
$parents = json_encode($resourcePermission->parentsIds());
?>
                         {{$resourcePermission->id."<br>"}}

                             @if(in_array($resourcePermission->id, $roleResourcePermissionsIds))
                                <option class="resourcepermission-can-also" value="{{$permission->id}}" data-parents="{{$parents}}" selected>{{$permission->display_name}}</option>
                             @else
                                 <option class="resourcepermission-can-also" value="{{$permission->id}}" data-parents="{{$parents}}">{{$permission->display_name}}</option>
                             @endif
                     @endforeach
                 </select>
             @endforeach
         </div>
     </div>
     <hr>
 public function manageRolePermissionsAction($id)
 {
     if (Auth::user() && Auth::user()->id == Config::get('laracancan.super_admin')) {
         $role = Role::find($id);
         $role->resourcePermissions()->detach();
         foreach (Resource::all() as $resource) {
             $permissions = Input::get($resource->id . "_resourcepermissions");
             if ($permissions != null) {
                 foreach ($permissions as $permission) {
                     $resourcePermission = Resourcepermission::where('permission_id', $permission)->where('resource_id', $resource->id)->first();
                     $role->resourcePermissions()->detach([$resourcePermission->id]);
                     $role->resourcePermissions()->attach([$resourcePermission->id]);
                     foreach ($resourcePermission->childResourcePermissions as $child) {
                         $role->resourcePermissions()->attach([$child->id => ['parent_id' => $resourcePermission->id]]);
                     }
                 }
             }
         }
         return redirect()->back()->with('flash_success', 'Permissions saved successfully!');
     }
     return response(view('laracancan::master.401'), 401);
 }
 public function canAlso($id)
 {
     if (Auth::user() && Auth::user()->id == Config::get('laracancan.super_admin')) {
         try {
             $resourcePermission = Resourcepermission::findorFail($id);
         } catch (ModelNotFoundException $e) {
             return "NOPERMISSION";
         }
         $resource = $resourcePermission->resource;
         $canAlsoes = Resourcepermission::where('resource_id', $resource->id)->where('id', '!=', $resourcePermission->id)->whereNull('parent_id')->whereNotIn('id', $resourcePermission->parentsIds())->get();
         return view('laracancan::permission.can_also')->with('resourcePermission', $resourcePermission)->with('canAlsoes', $canAlsoes)->with('resource', $resource);
     }
     return response(view('laracancan::master.401'), 401);
 }