jobmetric/laravel-package-core
A core foundation for building Laravel packages with JobMetric: shared service providers, configuration handling, migrations, and helper utilities that standardize structure and speed up development.
This release (1.26.0) is a small, additive update to the DTO layer, but it is the first thing to read if you are picking the package up.
dto() and dtoMany() alongside the existing DTO base class methods.context parameter on the DTO method used by the helpers,dto() / dtoMany() helper functions.$user = dto(UserData::class, $request->validated());
$users = dtoMany(UserData::class, $rows); // collection of UserData
Start with one DTO for a single endpoint, call dto() from the controller, and pass the result into an action/service. Add dtoMany() once you have an index endpoint. Do not retrofit the whole app on day one — the helper is thin sugar over the DTO constructor, so you get value from the first call site.
Helper-first in controllers, constructor-first in domain code. Use dto() / dtoMany() at the HTTP boundary where you have an array from validated() or a payload from a job. Inside services and domain objects, keep constructing DTOs explicitly so the dependency is visible and testable without the container.
Passing context. The new context parameter is the main reason to upgrade. Use it to thread request-scoped data (acting user, locale, tenant, source) into the DTO without adding it to the payload array:
$order = dto(OrderData::class, $payload, [
'user' => $request->user(),
'locale' => app()->getLocale(),
]);
Keep the context array shape consistent across the app — define a small DtoContext value object or a single Context::fromRequest() factory rather than hand-rolling arrays per call site.
Bulk conversion. dtoMany() for collections coming out of Eloquent or paginators. Map first, then convert, so you keep the collection's keys and lazy/eager semantics:
$users = dtoMany(UserData::class, $paginator->getCollection());
Nested DTOs. If your DTO method delegates to child DTOs, forward the context explicitly. This is the pattern most likely to be silently wrong after the 1.26.0 signature change.
Testing. Because context is now a parameter, you can assert on it: build a DTO with a fake context array and assert the resulting object, rather than mocking the container.
context parameter is a potential break. Adding an optional parameter is safe for callers but not for subclasses that declared the old signature without it — PHP will emit a compatibility error. Grep your DTOs for overrides before upgrading.dto() is a very common helper name. If you or another package already defines a global dto(), you will get a fatal redeclare. Check composer.json dependencies and your own app/helpers.php before rolling out.dto() but dropped in nested conversions. Add one test asserting a nested DTO receives context.dtoMany() return type. Confirm whether you get a Collection or an array in your installed version, and whether keys are preserved. Wrap with ->values() if downstream code expects a list.dd()-ing the context array inside the DTO method is the fastest way to confirm it arrives; the helpers otherwise swallow it without logging.^1.26 and read the diff on the next minor rather than floating *.How can I help you explore Laravel packages today?