Browse Source

feat: ✨ Added API-Route support for extensions

IceToast 2 năm trước cách đây
mục cha
commit
64cd6ac98c

+ 0 - 0
app/Extensions/PaymentGateways/PayPal/routes.php → app/Extensions/PaymentGateways/PayPal/web_routes.php


+ 0 - 0
app/Extensions/PaymentGateways/Stripe/routes.php → app/Extensions/PaymentGateways/Stripe/web_routes.php


+ 3 - 1
routes/api.php

@@ -34,6 +34,8 @@ Route::middleware('api.token')->group(function () {
     Route::get('/notifications/{user}', [NotificationController::class, 'index']);
     Route::get('/notifications/{user}/{notification}', [NotificationController::class, 'view']);
     Route::post('/notifications', [NotificationController::class, 'send']);
-    Route::delete('/notifications/{user}', [NotificationController::class, 'delete']);
     Route::delete('/notifications/{user}/{notification}', [NotificationController::class, 'deleteOne']);
+    Route::delete('/notifications/{user}', [NotificationController::class, 'delete']);
 });
+
+require __DIR__ . '/extensions_api.php';

+ 21 - 0
routes/extensions_api.php

@@ -0,0 +1,21 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+Route::group(['prefix' => 'extensions', 'middleware' => 'api.token'], function () {
+    // get all extensions that are inside App/Extensions
+    // It is important that the extensions are inside a folder with the name of the extension
+    // while those folders are inside Folders with the name of the type of extension like PaymentGateways, Themes, etc.
+    $extensionNamespaces = glob(app_path() . '/Extensions/*', GLOB_ONLYDIR);
+    $extensions = [];
+    foreach ($extensionNamespaces as $extensionNamespace) {
+        $extensions = array_merge($extensions, glob($extensionNamespace . '/*', GLOB_ONLYDIR));
+    }
+
+    foreach ($extensions as $extension) {
+        $routesFile = $extension . '/api_routes.php';
+        if (file_exists($routesFile)) {
+            include_once $routesFile;
+        }
+    }
+});

+ 4 - 4
routes/extensions.php → routes/extensions_web.php

@@ -3,7 +3,7 @@
 use Illuminate\Support\Facades\Route;
 
 Route::group(['prefix' => 'extensions'], function () {
-    
+
     // get all extensions that are inside App/Extensions
     // It is important that the extensions are inside a folder with the name of the extension
     // while those folders are inside Folders with the name of the type of extension like PaymentGateways, Themes, etc.
@@ -14,9 +14,9 @@ Route::group(['prefix' => 'extensions'], function () {
     }
 
     foreach ($extensions as $extension) {
-        $routesFile = $extension . '/routes.php';
+        $routesFile = $extension . '/web_routes.php';
         if (file_exists($routesFile)) {
             include_once $routesFile;
         }
-    }        
-});
+    }
+});

+ 1 - 1
routes/web.php

@@ -216,4 +216,4 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
     Route::get('/home', [HomeController::class, 'index'])->name('home');
 });
 
-require __DIR__ . '/extensions.php';
+require __DIR__ . '/extensions_web.php';