api.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. use Illuminate\Http\Request;
  3. /*
  4. |--------------------------------------------------------------------------
  5. | API Routes
  6. |--------------------------------------------------------------------------
  7. |
  8. | Here is where you can register API routes for your application. These
  9. | routes are loaded by the RouteServiceProvider within a group which
  10. | is assigned the "api" middleware group. Enjoy building your API!
  11. |
  12. */
  13. Route::prefix('v1')
  14. ->group(function () {
  15. // Admin
  16. Route::prefix('admin')
  17. ->middleware('admin')
  18. ->group(function () {
  19. Route::any('/{class}/{action}', function($class, $action) {
  20. $ctrl = \App::make("\\App\\Http\\Controllers\\Admin\\" . ucfirst($class) . "Controller");
  21. return \App::call([$ctrl, $action]);
  22. });
  23. });
  24. // User
  25. Route::prefix('user')
  26. ->middleware('user')
  27. ->group(function () {
  28. Route::any('/{action}', function($action) {
  29. $ctrl = \App::make("\\App\\Http\\Controllers\\User\\UserController");
  30. return \App::call([$ctrl, $action]);
  31. });
  32. Route::any('/{class}/{action}', function($class, $action) {
  33. $ctrl = \App::make("\\App\\Http\\Controllers\\User\\" . ucfirst($class) . "Controller");
  34. return \App::call([$ctrl, $action]);
  35. });
  36. });
  37. // Passport
  38. Route::prefix('passport')
  39. ->group(function () {
  40. Route::any('/{class}/{action}', function($class, $action) {
  41. $ctrl = \App::make("\\App\\Http\\Controllers\\Passport\\" . ucfirst($class) . "Controller");
  42. return \App::call([$ctrl, $action]);
  43. });
  44. });
  45. // No Auth
  46. Route::prefix('guest')
  47. ->group(function () {
  48. Route::any('/{class}/{action}', function($class, $action) {
  49. $ctrl = \App::make("\\App\\Http\\Controllers\\Guest\\" . ucfirst($class) . "Controller");
  50. return \App::call([$ctrl, $action]);
  51. });
  52. });
  53. // Client
  54. Route::prefix('client')
  55. ->middleware('client')
  56. ->group(function () {
  57. Route::any('/{action}', function($action) {
  58. $ctrl = \App::make("\\App\\Http\\Controllers\\Client\\ClientController");
  59. return \App::call([$ctrl, $action]);
  60. });
  61. Route::any('/{class}/{action}', function($class, $action) {
  62. $ctrl = \App::make("\\App\\Http\\Controllers\\Client\\" . ucfirst($class) . "Controller");
  63. return \App::call([$ctrl, $action]);
  64. });
  65. });
  66. // Server
  67. Route::prefix('server')
  68. ->group(function () {
  69. Route::any('/{class}/{action}', function($class, $action) {
  70. $ctrl = \App::make("\\App\\Http\\Controllers\\Server\\" . ucfirst($class) . "Controller");
  71. return \App::call([$ctrl, $action]);
  72. });
  73. });
  74. });