@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | public function getIndex() { |
| 33 | 33 | $data = []; |
| 34 | 34 | $data['result'] = DB::table("cb_modules")->get(); |
| 35 | - return view($this->view.'.index',$data); |
|
| 35 | + return view($this->view.'.index', $data); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function getAdd() { |
| 39 | 39 | $data = []; |
| 40 | 40 | $data['tables'] = cb()->listAllTable(); |
| 41 | - $data['module'] = (request('modules_id'))?cb()->find("cb_modules", request("modules_id")):null; |
|
| 41 | + $data['module'] = (request('modules_id')) ?cb()->find("cb_modules", request("modules_id")) : null; |
|
| 42 | 42 | return view($this->view.'.add', $data); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -51,17 +51,17 @@ discard block |
||
| 51 | 51 | $data = cb()->listAllColumns($table); |
| 52 | 52 | $pk = cb()->findPrimaryKey($table); |
| 53 | 53 | $result = []; |
| 54 | - foreach($data as $item) { |
|
| 54 | + foreach ($data as $item) { |
|
| 55 | 55 | |
| 56 | - if(Str::contains(strtolower($item),["title","name","label"])) { |
|
| 56 | + if (Str::contains(strtolower($item), ["title", "name", "label"])) { |
|
| 57 | 57 | $display = true; |
| 58 | - }else{ |
|
| 58 | + } else { |
|
| 59 | 59 | $display = false; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $result[] = [ |
| 63 | 63 | "column"=>$item, |
| 64 | - "primary_key"=>($pk==$item)?true:false, |
|
| 64 | + "primary_key"=>($pk == $item) ?true:false, |
|
| 65 | 65 | "display"=>$display |
| 66 | 66 | ]; |
| 67 | 67 | } |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | public function getColumns($table) |
| 72 | 72 | { |
| 73 | - if(request("modules_id")) { |
|
| 74 | - $module = cb()->find("cb_modules",request("modules_id")); |
|
| 75 | - if($module->last_column_build) { |
|
| 73 | + if (request("modules_id")) { |
|
| 74 | + $module = cb()->find("cb_modules", request("modules_id")); |
|
| 75 | + if ($module->last_column_build) { |
|
| 76 | 76 | return response()->json(json_decode($module->last_column_build)); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -80,56 +80,56 @@ discard block |
||
| 80 | 80 | $columns = cb()->listAllColumns($table); |
| 81 | 81 | $pk = cb()->findPrimaryKey($table); |
| 82 | 82 | $result = []; |
| 83 | - foreach($columns as $column) { |
|
| 84 | - if($column != $pk) { |
|
| 83 | + foreach ($columns as $column) { |
|
| 84 | + if ($column != $pk) { |
|
| 85 | 85 | |
| 86 | 86 | // Skip Column |
| 87 | - if($column == 'deleted_at') continue; |
|
| 87 | + if ($column == 'deleted_at') continue; |
|
| 88 | 88 | |
| 89 | 89 | // Check if any relation table candidate |
| 90 | 90 | $optionTable = ""; |
| 91 | - if(Str::substr(strtolower($column),-3,3) == "_id") { |
|
| 92 | - $relationTable = Str::substr($column,0,-3); |
|
| 93 | - if(Schema::hasTable($relationTable)) { |
|
| 91 | + if (Str::substr(strtolower($column), -3, 3) == "_id") { |
|
| 92 | + $relationTable = Str::substr($column, 0, -3); |
|
| 93 | + if (Schema::hasTable($relationTable)) { |
|
| 94 | 94 | $optionTable = $relationTable; |
| 95 | 95 | } |
| 96 | - }elseif (Str::substr(strtolower($column),0,3) == "id_") { |
|
| 97 | - $relationTable = Str::substr($column,3); |
|
| 98 | - if(Schema::hasTable($relationTable)) { |
|
| 96 | + }elseif (Str::substr(strtolower($column), 0, 3) == "id_") { |
|
| 97 | + $relationTable = Str::substr($column, 3); |
|
| 98 | + if (Schema::hasTable($relationTable)) { |
|
| 99 | 99 | $optionTable = $relationTable; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $label = trim(Str::title(str_replace(["id_","_id","_"]," ",$column))); |
|
| 103 | + $label = trim(Str::title(str_replace(["id_", "_id", "_"], " ", $column))); |
|
| 104 | 104 | $label = Str::singular($label); |
| 105 | 105 | $type = "text"; |
| 106 | 106 | |
| 107 | - if(Str::contains(strtolower($label),["photo","image","picture","gambar"])) { |
|
| 107 | + if (Str::contains(strtolower($label), ["photo", "image", "picture", "gambar"])) { |
|
| 108 | 108 | $type = "image"; |
| 109 | - }elseif (Str::contains(strtolower($label),["email","mail"])) { |
|
| 109 | + }elseif (Str::contains(strtolower($label), ["email", "mail"])) { |
|
| 110 | 110 | $type = "email"; |
| 111 | - }elseif (Str::contains(strtolower($label),["description","content","detail"])) { |
|
| 112 | - $type = "wysiwyg"; |
|
| 113 | - }elseif (Str::contains(strtolower($label),["price","money","grand_total","tax"])) { |
|
| 111 | + }elseif (Str::contains(strtolower($label), ["description", "content", "detail"])) { |
|
| 112 | + $type = "wysiwyg"; |
|
| 113 | + }elseif (Str::contains(strtolower($label), ["price", "money", "grand_total", "tax"])) { |
|
| 114 | 114 | $type = "money"; |
| 115 | - }elseif (Str::contains(strtolower($label),["quantity","qty","total","phone","telp"])) { |
|
| 115 | + }elseif (Str::contains(strtolower($label), ["quantity", "qty", "total", "phone", "telp"])) { |
|
| 116 | 116 | $type = "number"; |
| 117 | - }elseif (Str::contains(strtolower($label),["date"])) { |
|
| 117 | + }elseif (Str::contains(strtolower($label), ["date"])) { |
|
| 118 | 118 | $type = "date"; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if (Str::substr(strtolower($column),-3,3) == "_id") { |
|
| 121 | + if (Str::substr(strtolower($column), -3, 3) == "_id") { |
|
| 122 | 122 | $type = "select_table"; |
| 123 | 123 | } elseif (Str::substr($column, -3, 3) == "_at") { |
| 124 | 124 | $type = "datetime"; |
| 125 | - } elseif (Str::substr($column,0, 3) == "id_") { |
|
| 125 | + } elseif (Str::substr($column, 0, 3) == "id_") { |
|
| 126 | 126 | $type = "select_table"; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $columnAdd = "on"; |
| 130 | 130 | $columnEdit = "on"; |
| 131 | 131 | $columnMandatory = "on"; |
| 132 | - if(in_array($column,['created_at','updated_at'])) { |
|
| 132 | + if (in_array($column, ['created_at', 'updated_at'])) { |
|
| 133 | 133 | $columnAdd = ""; |
| 134 | 134 | $columnEdit = ""; |
| 135 | 135 | $columnMandatory = ""; |
@@ -174,41 +174,41 @@ discard block |
||
| 174 | 174 | public function postCreateMigration() |
| 175 | 175 | { |
| 176 | 176 | try { |
| 177 | - cb()->validation(['table_name','structures']); |
|
| 177 | + cb()->validation(['table_name', 'structures']); |
|
| 178 | 178 | |
| 179 | 179 | $tableName = request("table_name"); |
| 180 | 180 | |
| 181 | - if(!Schema::hasTable($tableName)) { |
|
| 181 | + if (!Schema::hasTable($tableName)) { |
|
| 182 | 182 | $filenameMigration = date("Y_m_d_His")."_".$tableName.".php"; |
| 183 | 183 | $createTemplate = file_get_contents(base_path("vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs/create.stub")); |
| 184 | 184 | $className = Str::studly($tableName); |
| 185 | 185 | $createTemplate = str_replace("DummyClass", $className, $createTemplate); |
| 186 | 186 | $createTemplate = str_replace("DummyTable", $tableName, $createTemplate); |
| 187 | - $createTemplate = str_replace("\$table->increments('id');","",$createTemplate); |
|
| 188 | - $createTemplate = str_replace("\$table->bigIncrements('id');","",$createTemplate); |
|
| 189 | - $createTemplate = str_replace("\$table->timestamps();","{structure}",$createTemplate); |
|
| 187 | + $createTemplate = str_replace("\$table->increments('id');", "", $createTemplate); |
|
| 188 | + $createTemplate = str_replace("\$table->bigIncrements('id');", "", $createTemplate); |
|
| 189 | + $createTemplate = str_replace("\$table->timestamps();", "{structure}", $createTemplate); |
|
| 190 | 190 | |
| 191 | 191 | $structureItems = ""; |
| 192 | 192 | |
| 193 | - if(request("timestamp")) { |
|
| 193 | + if (request("timestamp")) { |
|
| 194 | 194 | $structureItems .= "\$table->timestamps();\n\t\t\t"; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if(request("soft_deletes")) { |
|
| 197 | + if (request("soft_deletes")) { |
|
| 198 | 198 | $structureItems .= "\$table->softDeletes();\n\t\t\t"; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - foreach(request("structures") as $item) { |
|
| 201 | + foreach (request("structures") as $item) { |
|
| 202 | 202 | |
| 203 | 203 | $nullable = ""; |
| 204 | 204 | |
| 205 | - if(!in_array($item['type_data'],["bigIncrements","increments","mediumIncrements","smallIncrements"])) { |
|
| 205 | + if (!in_array($item['type_data'], ["bigIncrements", "increments", "mediumIncrements", "smallIncrements"])) { |
|
| 206 | 206 | $nullable = "->nullable()"; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if($item['length']) { |
|
| 209 | + if ($item['length']) { |
|
| 210 | 210 | $structureItems .= "\$table->".$item['type_data']."('".$item['field_name']."', ".$item['length'].")$nullable;\n\t\t\t"; |
| 211 | - }else{ |
|
| 211 | + } else { |
|
| 212 | 212 | $structureItems .= "\$table->".$item['type_data']."('".$item['field_name']."')$nullable;\n\t\t\t"; |
| 213 | 213 | } |
| 214 | 214 | } |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | } catch (CBValidationException $e) { |
| 230 | - return response()->json(['status'=>false,'message'=>$e->getMessage()]); |
|
| 230 | + return response()->json(['status'=>false, 'message'=>$e->getMessage()]); |
|
| 231 | 231 | } catch (\Exception $e) { |
| 232 | - return response()->json(['status'=>false,'message'=>$e->getMessage()]); |
|
| 232 | + return response()->json(['status'=>false, 'message'=>$e->getMessage()]); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return response()->json(['status'=>true,'message'=>'Migration successfully!']); |
|
| 235 | + return response()->json(['status'=>true, 'message'=>'Migration successfully!']); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | public function postCheckExistModule() |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | try { |
| 241 | 241 | cb()->validation(['name', 'table']); |
| 242 | 242 | |
| 243 | - if(DB::table("cb_modules")->where("table_name",request("table"))->where("name",request("name"))->count()) { |
|
| 243 | + if (DB::table("cb_modules")->where("table_name", request("table"))->where("name", request("name"))->count()) { |
|
| 244 | 244 | return response()->json(['status'=>true]); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | } catch (CBValidationException $e) { |
| 248 | - return response()->json(['status'=>false,'message'=>$e->getMessage()]); |
|
| 248 | + return response()->json(['status'=>false, 'message'=>$e->getMessage()]); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | return response()->json(['status'=>false]); |
@@ -254,30 +254,30 @@ discard block |
||
| 254 | 254 | public function postAddSave() { |
| 255 | 255 | |
| 256 | 256 | try { |
| 257 | - cb()->validation(['name', 'table','icon','columns']); |
|
| 257 | + cb()->validation(['name', 'table', 'icon', 'columns']); |
|
| 258 | 258 | |
| 259 | 259 | $module = (new ModuleGenerator(request('table'), request('name'), request('icon'), request("columns"), request("rebuild")))->make(); |
| 260 | 260 | |
| 261 | 261 | } catch (CBValidationException $e) { |
| 262 | - return response()->json(['status'=>false,'message'=>$e->getMessage()]); |
|
| 262 | + return response()->json(['status'=>false, 'message'=>$e->getMessage()]); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | return response()->json(['status'=>true, 'message'=>'Please remember that you can still modify the structure by edit the controller file '.$module['controller'].' :)']); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | public function getDelete($id) { |
| 269 | - $module = cb()->find("cb_modules",$id); |
|
| 269 | + $module = cb()->find("cb_modules", $id); |
|
| 270 | 270 | @unlink(app_path("Http/Controllers/".$module->controller.".php")); |
| 271 | 271 | DB::table("cb_modules")->where("id", $id)->delete(); |
| 272 | 272 | DB::table("cb_menus")->where("cb_modules_id", $id)->delete(); |
| 273 | - return cb()->redirectBack("The module has been deleted!","success"); |
|
| 273 | + return cb()->redirectBack("The module has been deleted!", "success"); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | public function getDeleteSoft($id) { |
| 277 | - $module = cb()->find("cb_modules",$id); |
|
| 277 | + $module = cb()->find("cb_modules", $id); |
|
| 278 | 278 | DB::table("cb_modules")->where("id", $id)->delete(); |
| 279 | 279 | DB::table("cb_menus")->where("cb_modules_id", $id)->delete(); |
| 280 | - return cb()->redirectBack("The module has been deleted!","success"); |
|
| 280 | + return cb()->redirectBack("The module has been deleted!", "success"); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | } |
| 284 | 284 | \ No newline at end of file |