Пример #1
0
 public function postPerms($id, Request $request)
 {
     $group = Groups::where('id', '=', $id)->live()->firstOrFail();
     if ($request->input('allperms') == "1") {
         GroupPerms::where("group_id", "=", $group->id)->delete();
         // remove all records
         GroupPerms::create(['group_id' => $group->id, 'controller' => null, 'action' => null]);
     } elseif (!is_array($request->input('perms'))) {
         GroupPerms::where("group_id", "=", $group->id)->delete();
         // remove all records
     } else {
         $currentPerms = [];
         foreach (GroupPerms::where('group_id', '=', $group->id)->get() as $row => $p) {
             $controllername = strlen($p->controller) < 1 ? "all" : $p->controller;
             $actionname = strlen($p->action) < 1 ? "all" : $p->action;
             $currentPerms[$controllername . "___" . $actionname] = $p->id;
         }
         $postperms = $request->input('perms');
         if (is_array($postperms)) {
             foreach ($postperms as $r => $perm) {
                 if (isset($currentPerms[$perm])) {
                     unset($currentPerms[$perm]);
                 } else {
                     $str = explode('___', $perm);
                     if ($str[0] == "all") {
                         $str[0] = null;
                     }
                     if ($str[1] == "allmethods") {
                         $str[1] = null;
                     }
                     GroupPerms::create(['group_id' => $group->id, 'controller' => $str[0], 'action' => $str[1]]);
                 }
             }
             GroupPerms::whereIn('id', array_values($currentPerms))->delete();
         }
     }
     return redirect('settings/groups/data/perms/' . $group->id)->with('custom_success', trans('app.perms') . trans('app.successfully_saved'));
 }