net-code / laravel-kit
Small, reusable conventions for building Laravel REST APIs: a Clock port, sort direction, paginated-response envelope, ISO country-code rule, an OpenAPI error-status attribute, and a base context service provider.
v0.3.0
2026-07-11 04:51 UTC
Requires
- php: ^8.5
- illuminate/contracts: ^13.0
- illuminate/http: ^13.0
- illuminate/support: ^13.0
- symfony/intl: ^8.1
Requires (Dev)
- illuminate/translation: ^13.0
- laravel/pint: ^1.27
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.2
README
Small, reusable conventions for building Laravel REST APIs — the framework-level glue that would otherwise be copy-pasted between projects. Extracted from the net-tech portfolio API.
No service provider, no config, no magic: just a handful of classes you reach for directly.
Install
composer require net-code/laravel-kit
What's inside
| Class | Purpose |
|---|---|
NetCode\Kit\Clock / SystemClock |
Injectable time port + system implementation. Bind Clock to SystemClock (or a fixed clock in tests). |
NetCode\Kit\SortDirection |
asc / desc string enum for list queries. |
NetCode\Kit\Http\PaginatedResponse |
Builds the {meta, links} half of a paginated JSON envelope from the request + page numbers. |
NetCode\Kit\Validation\CountryCode |
Validation rule accepting any ISO 3166-1 alpha-2 country code. |
NetCode\Kit\ContextServiceProvider |
Base service provider with registerBindings() / bootContext() hooks for modular-monolith bounded contexts. |
Usage
use NetCode\Kit\Clock; use NetCode\Kit\SystemClock; $this->app->bind(Clock::class, SystemClock::class);
use NetCode\Kit\Http\PaginatedResponse; return response()->json([ 'data' => $rows, ...PaginatedResponse::meta($request, $page, $perPage, $total), ]);
use NetCode\Kit\Validation\CountryCode; $request->validate(['country' => ['required', new CountryCode]]);
Scramble/OpenAPI operation transformers previously shipped here have moved to the dedicated
net-code/laravel-scramblepackage, keeping this kit dependency-light.
License
MIT