diff --git a/Extension.php b/Extension.php index de20fa2..8048b51 100755 --- a/Extension.php +++ b/Extension.php @@ -5,6 +5,7 @@ use Admin\Models\Customers_model; use Admin\Models\Users_model; use Dingo\Api\Auth\Auth; +use Igniter\Api\Classes\ScopeFactory; use Igniter\Flame\Database\Model; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Contracts\Http\Kernel; @@ -12,6 +13,7 @@ use Illuminate\Support\Facades\RateLimiter; use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful; use Laravel\Sanctum\Sanctum; +use League\Fractal\Manager; use System\Classes\BaseExtension; /** @@ -193,6 +195,10 @@ public function registerApiResources() */ protected function registerResponseFactory() { + $this->app->bind(Manager::class, function () { + return new Manager(new ScopeFactory); + }); + $this->app->alias('api.response', Classes\ResponseFactory::class); $this->app->singleton('api.response', function ($app) { diff --git a/classes/Scope.php b/classes/Scope.php new file mode 100644 index 0000000..522cb86 --- /dev/null +++ b/classes/Scope.php @@ -0,0 +1,26 @@ +getKey(); + + return [$transformedData, $includedData]; + } +} diff --git a/classes/ScopeFactory.php b/classes/ScopeFactory.php new file mode 100644 index 0000000..49510d2 --- /dev/null +++ b/classes/ScopeFactory.php @@ -0,0 +1,15 @@ + array_get($data, $keyName), - ]); - - unset($data[$keyName]); - } - - return parent::item($resourceKey, $data); - } }