user()->role != 1) { return view('errors.404'); } if ($id == 'admin') { $datas['title'] = 'Menu Management'; $datas['getMenu'] = \DB::select("SELECT * from menu order by seq"); } $datas['table'] = route('data.menu',$id); $datas['admin_menu_get'] = route('menu.menu_get',$id); $datas['admin_menu_store'] = route('menu.store',$id); return $this->bsGetView('content.menu_admin.index',$datas); } public function admin_data($id) { if (Auth::guard('admin')->user()->role != 1) { return view('errors.404'); } if ($id == 'admin') { $data = \DB::select("SELECT *,id as list_menu FROM groups_admin order by id desc"); }else{ $data = \DB::select("SELECT user_type_name as description,user_type_uid as list_menu FROM reff_user_type order by user_type_uid desc"); } return DataTables::of($data) ->addColumn('action', function ($data) { return '
'; }) ->editColumn('list_menu',function($data) use($id) { if ($id == 'admin') { $getMenu = \DB::select("SELECT * from menu_privilege rrm join menu rm on rm.menu_uid = rrm.menu_uid where group_id = ? and has_children = 't' order by rm.menu_uid",[$data->list_menu]); $menu_list = ''; foreach ($getMenu as $key => $v) { $menu_list .= ''.$v->menu.''; } }else{ $getMenu = \DB::select("SELECT * from privilege rrm join menu_cms rm on rm.menu_cms_uid = rrm.menu_cms_uid where user_type_uid = ? and has_children = 't' order by rm.menu_cms_uid",[$data->list_menu]); $menu_list = ''; foreach ($getMenu as $key => $v) { $menu_list .= ''.$v->menu_cms.''; } } return $menu_list; }) ->rawColumns(['list_menu','action']) ->make(true); } public function admin_menu_get(Request $request,$id) { if (Auth::guard('admin')->user()->role != 1) { return view('errors.404'); } if ($id == 'admin') { $data = \DB::select("SELECT * FROM menu_privilege where group_id = ?",[$request->post('id')]); }else{ $data = \DB::select("SELECT *,menu_cms_uid as menu_uid FROM privilege where user_type_uid = ?",[$request->post('id')]); } return json_encode($data); } public function admin_store(Request $request,$id) { if (Auth::guard('admin')->user()->role != 1) { return view('errors.404'); } if ($id == 'admin') { DB::table('menu_privilege')->where('group_id', $request->post('get_id'))->delete(); $menu_id = $request->post('menu_id'); if ($menu_id) { foreach ($menu_id as $key => $v) { // $seq = DB::table('menu_privilege')->max('id'); DB::table('menu_privilege')->insert([ // 'id' => $seq+1, 'group_id' => $request->post('get_id'), 'menu_uid' => $v ]); } } }else{ DB::table('privilege')->where('user_type_uid', $request->post('get_id'))->delete(); $menu_id = $request->post('menu_id'); if ($menu_id) { foreach ($menu_id as $key => $v) { // $seq = DB::table('menu_privilege')->max('id'); DB::table('privilege')->insert([ // 'id' => $seq+1, 'user_type_uid' => $request->post('get_id'), 'menu_cms_uid' => $v ]); } } } return response()->json([ 'rc' => 0, 'rm' => "Berhasil" ]); } }