initData($request,$route); return $data; } public function index(Request $request) { //INIT $init = $this->getInit($request,$request->get('type')); $route = $init['route']; $param['title'] = $init['title']; $param['tableHead'] = $init['tableHead']; $param['head'] = $init['head']; $param['detail'] = empty($init['detail'])?false:true; if (isset($init['headAlias'])) { $param['headAlias'] = $init['headAlias']; }else{ $param['headAlias'] = null; } $param['bisaAdd'] = $init['bisaAdd']; $param['adaDetail'] = $init['adaDetail']; $view = 'content.ref.index'; //END INIT $param['table'] = route('ref.data')."?type=".$route; $param['delete'] = route('ref.delete')."?type=".$route; $param['edit'] = route('ref.edit')."?type=".$route; $param['store'] = route('ref.store')."?type=".$route; $param['storeCustom'] = route('ref.storeCustom')."?type=".$route; // $param['setActive'] = route('ref.setActive')."?type=".$route; $param['vForm'] = 'content.ref.'.$route.'.form'; $param['vAction'] = 'content.ref.'.$route.'.action'; $param['vFormDet'] = 'content.ref.'.$route.'.formDet'; $param['init'] = $init; // return view('home')->nest('child',$view, $param); return $this->bsGetView($view, $param); } public function data(Request $request) { $init = $this->getInit($request,$request->get('type')); $data = $init['data_table']; $modelName = '\\App\Models\\'.$init['route'].'Model'; $model = new $modelName; $dt = $model->getDT($data,$init); $dt->addColumn('action', function ($data) use($init) { if(is_array($init['db_key'])) { if(count($init['db_key'])>1) { $keyCustom = ''; foreach($init['db_key'] as $i => $dbKey) { if(($i+1)==count($init['db_key'])) { $keyCustom.= $data->{$dbKey}; } else { $keyCustom.= $data->{$dbKey}.'|'; } } $param['id_key'] = $keyCustom; } } else { $param['id_key'] = $data->{$init['db_key']}; } $param['data'] = $data; //SET BUTTON return $this->getButtonAction($init['actButton'],$param); }); $dt->rawColumns(['is_active','created_at','updated_at','action']); return $dt->make(true); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // //GET INIT DB::beginTransaction(); try { //code... $init = $this->getInit($request,$request->get('type')); $get_id = $request->input('get_id'); $setField = $init['set_field']; $timestamps = $init['timestamps']; //IF EDIT DATA if ($get_id) { if ($timestamps) { $setField['updated_at'] = date('Y-m-d H:i:s'); } if(is_array($init['db_key'])) { if(count($init['db_key'])>1) { $data = DB::table($init['db'])->where(function($query) use ($request, $init, $get_id) { $primaryKey = explode('|',$get_id); foreach($init['db_key'] as $k => $i) { $query->where($i, $primaryKey[$k]); } })->update($setField); } } else { DB::table($init['db'])->where($init['db_key'], $get_id)->update($setField); } //IF ADD DATA }else { if ($timestamps) { $setField['created_at'] = date('Y-m-d H:i:s'); $setField['updated_at'] = date('Y-m-d H:i:s'); } if ($init['serial']===false) { $getId = DB::table($init['db'])->max('id'); $setField['id'] = $getId+1; } if ($init['seq']) { $seq = DB::Table($init['db'])->max('seq'); $setField['seq'] = $seq+1; } DB::table($init['db'])->insert($setField); } DB::commit(); return response()->json([ 'rc' => 0, 'rm' => "Berhasil" ]); } catch (\Throwable $e) { //throw $th; DB::rollBack(); return response()->json([ 'rc' => 99, 'data' => $e->getMessage() ]); } catch (QueryException $e) { DB::rollBack(); return response()->json([ 'rc' => 500, 'data' => $e->getMessage() ]); } } public function storeCustom(Request $request) { $init = $this->getInit($request,$request->get('type')); $modelName = '\\App\Models\\'.$init['route'].'Model'; $model = new $modelName; return $model->storeCustom($request); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(Request $request) { // $init = $this->getInit($request,$request->get('type')); return response()->json([ 'rc' => 0, 'data' => $init['get_data_edit'] ]); } public function delete(Request $request) { $init = $this->getInit($request,$request->get('type')); $get_id = $request->input('id'); DB::beginTransaction(); try { //code... if(is_array($init['db_key'])) { if(count($init['db_key'])>1) { $data = DB::table($init['db'])->where(function($query) use ($request, $init, $get_id) { $primaryKey = explode('|',$get_id); foreach($init['db_key'] as $k => $i) { $query->where($i, $primaryKey[$k]); } })->delete(); } } else { if($request->get('type')=='Model') { ModelingTaskModel::where('model_id', $get_id)->delete(); } DB::table($init['db'])->where($init['db_key'], $get_id)->delete(); } DB::commit(); return response()->json([ 'rc' => 0, 'rm' => 'Data Berhasil Dihapus' ]); } catch (\Throwable $e) { DB::rollBack(); if($e->getCode()=='23503') { return response()->json([ 'rc' => 99, 'rm' => 'Data Tidak Dapat Dihapus Karena Memiliki Relasi Dengan Data Lain!' ]); } else { return response()->json([ 'rc' => 500, 'rm' => $e->getMessage() ]); } } catch (QueryException $e) { DB::rollBack(); if($e->getCode()=='23503') { return response()->json([ 'rc' => 99, 'rm' => 'Data Tidak Dapat Dihapus Karena Memiliki Relasi Dengan Data Lain!' ]); } else { return response()->json([ 'rc' => 500, 'rm' => $e->getMessage() ]); } } } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } public function getButtonAction($typeButton,$param) { $editBtn =""; $detailBtn =""; $ActiveBtn = ""; $mapsBtn = ""; $hapusBtn = ""; //MAP BUTTON if ( in_array("maps", $typeButton)) { $mapsBtn = '