Laravel Packages

Intelligent Parsing and Formatting of Names in PHP Applications

Published
Intelligent Parsing and Formatting of Names in PHP Applications image

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

👩‍💻 Get started by visiting the GitHub repo: hosmelq/name-of-person

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

tinkerwell logo
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article