
Name of Person is a PHP package inspired by Basecamp’s name_of_person Ruby gem, which gives you intelligent parsing and multiple formatting options.
Handle person names in your PHP applications with elegant formatting options. Transform names between multiple presentation formats. This package provides a clean, type-safe way to parse, store, manipulate, and display person names consistently across your application.
use HosmelQ\NameOfPerson\PersonName;
// Direct instantiation with first and last name.
$name = new PersonName(‘Eric’, ‘Barnes’);
// From full name strings.
$parsed = PersonName::fromFull(‘Yannick Lyn Fatt’);
echo $parsed->first; // “Yannick”
echo $parsed->last; // “Fatt”
// Handles single names.
$single = PersonName::fromFull(‘Harris’);
echo $single->first; // “Harris”
echo $single->last; // null
This package also has Laravel support for casts that you can use with your models. The cast supports string-based cast config as well as a fluent method, and JSON serialization:
use HosmelQ\NameOfPerson\PersonNameCast;
// Default configuration – uses first_name and last_name columns
class User extends Model
{
protected function casts(): array
{
return [
‘name’ => PersonNameCast::class,
];
}
}
$user->name = ‘Eric L. Barnes’;
echo $user->name->familiar(); // “Eric B.”
echo $name->initials(); // “ELB”
echo $name->possessive(‘first’); // Eric’s
// Fluent cast
return [
‘author_name’ => PersonNameCast::using(‘author_first’, ‘author_last’),
];
Main Features
Multiple Format Options: nine different ways to display names (full, familiar, abbreviated, initials, sorted, possessive, mentionable)
Smart Parsing: Intelligently handles full name strings and edge cases
Unicode Support: Full international name support with proper multibyte handling
Pure PHP: Core functionality works in any PHP project
Laravel Integration: Native Eloquent casting for seamless database integration
NTSPL has established itself as a trusted provider of high-quality PHP development services. With a focus on performance, scalability, and clean coding practices, the company consistently delivers solutions that meet the unique needs of its clients. Whether it’s building custom web applications, optimizing existing systems, or integrating powerful features, NTSPL’s expertise in PHP ensures reliable and effective results. For businesses seeking dependable development partners, NTSPL stands out as a strong choice.