blaspsoft/onym
Onym is a Laravel package for working with personal names: parse full names into first, middle, and last components, handle salutations and suffixes, and format or normalize name data for clean storage, reliable search, and consistent display across your application.
Install the package via Composer and publish its config if you need to override defaults:
composer require blaspsoft/onym
php artisan vendor:publish --tag=onym-config
The first place to look is config/onym.php (or the package’s config file after publishing). It typically exposes default strategies, separators, length limits, and allowed characters. Also inspect the package source under vendor/blaspsoft/onym/src for the strategy classes and the main manager/facade — documentation may be thinner than the code itself.
Your first use case should be upload naming. Instead of trusting $request->file('avatar')->getClientOriginalName(), generate a deterministic, collision-resistant name:
use BlaspSoft\Onym\Facades\Onym;
$filename = Onym::strategy('hash')->generate($file);
// e.g. 9f86d081884c7d65.jpg
$path = $file->storeAs('avatars', $filename, 'public');
If the package exposes a helper or Onym::filename() method, use that in a quick Tinker session to confirm the output format before wiring it into controllers or jobs.
Strategy selection per context. Use different strategies for different file types: hashed names for public uploads, slug-based names for human-readable assets, date-prefixed names for reports or exports, and UUID/random names for temporary or user-private files. Avoid a single global default if your app handles mixed media.
$publicName = Onym::strategy('slug')->from($file->getClientOriginalName())->generate();
$reportName = Onym::strategy('date')->prefix('report')->generate();
$tempName = Onym::strategy('uuid')->generate();
Wrap filename generation in a small application service. Don’t scatter Onym::... calls across controllers, jobs, and observers. Create an UploadNamingService that returns a filename and optionally a full storage path. This makes it easy to change strategies later and to test naming behaviour independently.
class UploadNamingService
{
public function forPublicUpload(UploadedFile $file): string
{
return Onym::strategy('hash')
->extension($file->getClientOriginalExtension())
->generate();
}
}
Use model events or observers for persisted files. If your Document model has a path attribute, generate the filename in a creating observer and store it before the file is moved. Combine this with a temporary upload disk so the final name is only assigned once validation passes.
Integrate with Storage and storeAs. Generate the name first, then pass it to Laravel’s filesystem API. Keep the disk name in config rather than hard-coding public or s3.
$name = $namingService->forPublicUpload($request->file('document'));
$path = $request->file('document')->storeAs('documents', $name, config('filesystems.default'));
Chain strategies when the package supports it. If the package offers a fluent builder, compose readable names with a uniqueness suffix: slug + short random token, or date + hash. Check the source for methods like prefix(), suffix(), extension(), length(), and separator().
Test the generated shape, not the exact value. For random or time-based strategies, assert regex patterns, extension preservation, length limits, and uniqueness across multiple calls. For deterministic strategies, assert exact output.
Use it in seeders, imports, and exports. Day-to-day leverage isn’t only HTTP uploads. Use Onym to name generated CSV exports, seeded fixture files, queued report PDFs, and temporary archives. This keeps filenames consistent across CLI and web contexts.
slug or date strategy can collide under load. Pair it with a random suffix or hash if the file must be unique. If the package provides a unique() modifier, verify whether it checks the filesystem or only appends randomness.FileExistsException with a retry loop..JPG vs .jpg) if your storage layer is case-sensitive.config/onym.php, run php artisan config:clear in development. In production, remember that config:cache will freeze defaults, so deploy config changes deliberately.config/app.php aliases and the service provider.vendor/blaspsoft/onym. If tests are missing, write your own characterisation tests around the strategies you rely on.storeAs call uses the same disk you validated against.How can I help you explore Laravel packages today?