CrudController.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Http\Controllers\Admin\Base;
  3. use App\Http\Controllers\Admin\Controller;
  4. use App\Services\CRUD\CRUD;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Services\Admin\Menus;
  7. use Request;
  8. class CrudController extends Controller
  9. {
  10. function create()
  11. {
  12. if (Request::method() == 'POST') {
  13. return $this->_createSave();
  14. }
  15. $schema = env("DB_DATABASE");
  16. $tables = DB::select("SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA='$schema'");
  17. $MenusTrees = (new Menus())->getMenusTree();
  18. return view('admin.base.crud.create', compact('tables', 'MenusTrees'));
  19. }
  20. private function _createSave()
  21. {
  22. $data = Request::all();
  23. $obj = new CRUD();
  24. $ok = $obj->create($data);
  25. if ($ok) {
  26. $this->showMessage("操作成功");
  27. } else {
  28. $this->showWarning("操作失败:" . $obj->getMessage());
  29. }
  30. }
  31. public function getTable()
  32. {
  33. $table = request()->get('table');
  34. $schema = env("DB_DATABASE");
  35. $data = DB::select("SELECT COLUMN_NAME,COLUMN_KEY FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='{$schema}' AND TABLE_NAME='{$table}';");
  36. }
  37. public function checkModelPath($modelPath = null)
  38. {
  39. if (!$modelPath) {
  40. $modelPath = request()->get('path');
  41. }
  42. $modelPath = app_path() . "/Models/" . $modelPath . ".php";
  43. if (file_exists($modelPath)) {
  44. return json_encode(['status' => FAILURE_CODE, 'msg' => '注意!!Model文件已存在,系统重复不会创建!!!']);
  45. } else {
  46. return json_encode(['status' => SUCESS_CODE]);
  47. }
  48. }
  49. public function checkServicePath($modelPath = null)
  50. {
  51. if (!$modelPath) {
  52. $modelPath = request()->get('path');
  53. }
  54. $modelPath = app_path() . "/Repositories/" . $modelPath . ".php";
  55. if (file_exists($modelPath)) {
  56. return json_encode(['status' => FAILURE_CODE, 'msg' => '注意!!Service文件已存在,系统重复不会创建!!!']);
  57. } else {
  58. return json_encode(['status' => SUCESS_CODE]);
  59. }
  60. }
  61. public function checkControllerPath($modelPath = null)
  62. {
  63. if (!$modelPath) {
  64. $modelPath = request()->get('path');
  65. }
  66. $modelPath = app_path() . "/Http/Controllers/Admin/" . $modelPath . ".php";
  67. if (file_exists($modelPath)) {
  68. return json_encode(['status' => FAILURE_CODE, 'msg' => '注意!!Controller文件已存在,系统重复不会创建!!!']);
  69. } else {
  70. return json_encode(['status' => SUCESS_CODE]);
  71. }
  72. }
  73. public function checkPath($modelPath = null)
  74. {
  75. if (!$modelPath) {
  76. $modelPath = request()->get('path');
  77. }
  78. $modelPath = app_path() . "/Http/Controllers/Admin/" . $modelPath . ".php";
  79. if (file_exists($modelPath)) {
  80. return json_encode(['status' => FAILURE_CODE, 'msg' => '注意!!Controller文件已存在,系统重复不会创建!!!']);
  81. } else {
  82. return json_encode(['status' => SUCESS_CODE]);
  83. }
  84. }
  85. }