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

masteringlaravel logo
Laravel Code Review

Get expert guidance in a few days with a Laravel code review

Visit Laravel Code Review

The latest

View all →
Image Dominant Color and HEIC Support in Laravel 13.24 image

Image Dominant Color and HEIC Support in Laravel 13.24

Read article
Official Laravel Zed Extension: LSP for PHP & Blade image

Official Laravel Zed Extension: LSP for PHP & Blade

Read article
Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD image

Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD

Read article
PhpStorm 2026.2 Released image

PhpStorm 2026.2 Released

Read article
Laravel Doctor: Diagnose Your App With One Artisan Command image

Laravel Doctor: Diagnose Your App With One Artisan Command

Read article
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article