trinity/utils
Trinity Utils is a compact Laravel/PHP utility package that bundles handy helpers for everyday development. It keeps common tasks concise and readable, trimming boilerplate without pulling in heavy dependencies, and is easy to drop into existing projects.
Before writing any code against trinity/utils, do a 15-minute source audit. The package is a single-maintainer utility library with one star, zero dependents, and no release since August 2017, so its public API is whatever happens to be in src/ — not what a README claims. Open composer.json first and check the require block: confirm the PHP constraint and the Laravel/Illuminate version range. A 2017 package will typically pin php: >=5.6 and illuminate/support: ~5.x, which will not install cleanly on Laravel 10/11 without --ignore-platform-reqs or a fork.
Minimal install on a legacy-compatible app:
composer require trinity/utils
If the package ships a service provider, Laravel's package discovery should register it automatically. If not (common for 2017 packages), add it manually to config/app.php under providers. Check for a config/ directory in the package root; if one exists, publish it:
php artisan vendor:publish --provider="Trinity\Utils\UtilsServiceProvider"
First use case: pick the one utility you actually need, wrap it in a thin application-level helper, and call that helper from a single feature. Do not sprinkle Trinity\Utils\... calls across controllers. Read the class you plan to use end-to-end, because utility packages of this vintage tend to have static methods with implicit assumptions (global config(), app() resolution, hardcoded formats) that are not documented.
If the app targets Laravel 9+, the honest recommendation is to copy the one or two functions you need into app/Support/ rather than adding the dependency. You get the behaviour, you control the PHP version, and you avoid an unmaintained transitive dependency.
Adapter/wrapper pattern (recommended). Bind the package behind your own interface so a future fork or removal is a one-file change:
// app/Support/Contracts/Formatter.php
interface Formatter { public function clean(string $value): string; }
// app/Support/TrinityFormatter.php
final class TrinityFormatter implements Formatter
{
public function clean(string $value): string
{
return \Trinity\Utils\Formatter::clean($value); // verify actual API in src/
}
}
Register the binding in a service provider and inject Formatter everywhere. When the package breaks on a PHP upgrade, you swap the implementation without touching call sites.
Use in form requests and validation. Utility libraries often carry string/array normalisers that pair well with prepareForValidation():
protected function prepareForValidation(): void
{
$this->merge(['phone' => app(Formatter::class)->clean($this->phone)]);
}
Console and job usage. Because these are typically static, pure helpers, they are safe inside queued jobs and Artisan commands — but verify no helper touches the session, request, or auth globals before using them off the HTTP path. Grep the source for request(), auth(), session(), and $_SERVER.
Test harness around the package. Add a small characterisation test suite that pins the behaviour you depend on. This is your regression net if you later fork the package under a path repository:
it('normalises the values we rely on', function () {
expect(app(Formatter::class)->clean(' A '))->toBe('A');
});
Fork-and-path workflow. If you need the package but must modernise it, fork it, bump the composer.json constraints, and reference it locally:
"repositories": [{ "type": "path", "url": "../forks/trinity-utils" }],
"require": { "trinity/utils": "dev-main" }
This is the realistic long-term path for a package last released in 2017.
each() on arrays, create_function). Run composer why-not and a full test suite immediately after install.composer require as a green light.classmap or files autoloading with global helper functions. Global helpers collide silently with Laravel's own Str/Arr helpers or with other packages; grep composer.json for "files" before installing.config('trinity.*') at construction time, run php artisan config:cache in a staging environment to confirm the values survive — packages that call env() directly outside config files will break under caching.static properties can leak between tests and between queued jobs in long-running workers (Octane, Horizon). Reset or avoid them in tearDown().composer.lock, run composer audit, and avoid passing untrusted user input through helpers you have not read.final/static classes, you cannot decorate cleanly. The wrapper pattern above is your only real seam; do not attempt to subclass package classes unless you have confirmed they are non-final and use protected members.app/Support/ and drop the dependency. Keep the characterisation tests from the section above so the inline copy is verifiably equivalent.How can I help you explore Laravel packages today?