Skip to content

Commit

Permalink
added collection to JsonResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
nikuscs committed Nov 7, 2024
1 parent 081426d commit 722dfae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/Macros/CollectionMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Flavorly\LaravelHelpers\Macros;

use Flavorly\LaravelHelpers\Contracts\RegistersMacros;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
Expand All @@ -13,6 +14,7 @@ public static function register(): void
{
self::paginate();
self::orderByIds();
self::toJsonResponse();
}

public static function paginate(): void
Expand Down Expand Up @@ -73,4 +75,11 @@ public static function orderByIds(): void
});
}
}

public static function toJsonResponse(): void
{
Collection::macro('toJsonResponse', function (): JsonResponse {
return response()->json($this);
});
}
}
Loading

0 comments on commit 722dfae

Please sign in to comment.