PHPackages                             taylornetwork/name-formatter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. taylornetwork/name-formatter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

taylornetwork/name-formatter
============================

A name formatter for Laravel

1.3.3(7y ago)365MITPHPPHP &gt;=7.1

Since Nov 18Pushed 7y ago1 watchersCompare

[ Source](https://github.com/taylornetwork/name-formatter)[ Packagist](https://packagist.org/packages/taylornetwork/name-formatter)[ RSS](/packages/taylornetwork-name-formatter/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (3)Versions (7)Used By (0)

Name Formatter for Laravel
==========================

[](#name-formatter-for-laravel)

A customizable name formatter class for Laravel.

Install
-------

[](#install)

Via Composer

```
$ composer require taylornetwork/name-formatter
```

### Publish Config

[](#publish-config)

```
$ php artisan vendor:publish
```

This will add `nameformatter.php` to your `config` directory

Usage
-----

[](#usage)

Create a new instance of the class by passing it an instance of `Illuminate\Eloquent\Model` and call `format()`

Let's say we have a Customer model at `App\Customer`

```
use Illuminate\Eloquent\Model;

class Customer extends Model
{
	protected $fillable = [
		'first_name', 'last_name', 'address',
	];
}
```

We want to add a `fullName` attribute to our customer. We can create a getAttribute method Laravel will use to create the attribute for us. See [Laravel Eloquent Documentation](https://laravel.com/docs/5.3/eloquent) for more information.

```
use Illuminate\Eloquent\Model;
use TaylorNetwork\Formatters\Name\Formatter;

class Customer extends Model
{
	protected $fillable = [
		'first_name', 'last_name', 'address',
	];

	public function getFullNameAttribute()
	{
		$formatter = new Formatter($this);
		return $formatter->format();
	}
}
```

Get the customer's full name

```
$customer = App\Customer::create([
	'first_name' => 'John',
	'last_name' => 'Doe',
	'address' => '123 Main Street'
]);

echo $customer->fullName;
```

Returns

```
'John Doe'
```

By default the `Formatter` class will concatenate the `first_name` attribute, a space and the `last_name` attribute.

### Trait

[](#trait)

This package includes a trait you can add to your model that will add a `fullName` attribute.

```
use Illuminate\Eloquent\Model;
use TaylorNetwork\Formatters\Name\FormatsFullName;

class Customer extends Model
{
	use FormatsFullName;

	protected $fillable = [
		'first_name', 'last_name', 'address',
	];
}
```

You can then access the full name using the default configuration by:

```
echo $customer->fullName;
```

#### Override Formatter Config

[](#override-formatter-config)

You can override the formatter config when using the trait by overriding the `formatterConfig` method in your model

```
use Illuminate\Eloquent\Model;
use TaylorNetwork\Formatters\Name\FormatsFullName;

class Customer extends Model
{
    use FormatsFullName;

	protected $fillable = [
		'first_name', 'last_name', 'address',
	];

	public function formatterConfig(&$formatter)
	{
	    $formatter->style('L, F');
	}
}
```

### Available Methods

[](#available-methods)

#### format ()

[](#format-)

Returns formatted name.

#### map (string | array $field, string | null $modelField)

[](#map-string--array-field-string--null-modelfield)

By default the `Formatter` class will look for a `first_name` and `last_name` attribute on the model it was passed. If the model you are passing it has different attribute names fot first and last names you can either pass an associative array to the `map` function or two strings.

For a model with a first name attribute named `fName` and a last name attribute named `lName`

```
$formatter = new TaylorNetwork\Formatters\Name\Formatter($model);

$formatter->map([ 'first_name' => 'fName', 'last_name' => 'lName' ])->format();

// OR

$formatter->map('first_name', 'fName')->map('last_name', 'lName')->format();
```

#### style (string $style)

[](#style-string-style)

By default the `Formatter` class will format names as `$first_name . ' ' . $last_name`You can override the style with the `style` function. `style` accepts a string with the formatting you would like `Formatter` to use

KeyDescriptionExample: `'John Doe'``'F'`The full first name`'John'``'L'`The full last name`'Doe'``'f'`The first initial`'J'``'l'`The last initial`'D'`*Any other characters in the string will appear in the formatted name*

##### Examples

[](#examples)

```
$model->first_name = 'John';
$model->last_name = 'Doe';

$formatter = new TaylorNetwork\Formatters\Name\Formatter($model);
```

To get the first initial and last name

```
$formatter->style('f L')->format();

// Returns

'J Doe'
```

To get the last initial, the first name

```
$formatter->style('l, F')->format();

// Returns

'D, John'
```

To get the first and last initials

```
$formatter->style('fl')->format();

// Returns

'JD'
```

You can even add other characters to the style string

```
$formatter->style('F_L')->format();

// Returns

'John_Doe'
```

Every key in the string is replaced, so you could do something like this. (Though I don't know why you would)

```
$formatter->style('fffF lllL')->format();

// Returns

'JJJJohn DDDDoe'
```

Config
------

[](#config)

Once you run `php artisan vendor:publish` the config file `nameformatter.php` will be in your `config` directory. There you can set the defaults you want in terms of format style, field map, etc.

Credits
-------

[](#credits)

- Author: [Sam Taylor](https://github.com/taylornetwork)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~164 days

Recently: every ~182 days

Total

6

Last Release

2689d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

1.3.3PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/83340094473f0bf5b2cf062bf394df221a52a30aa0e21cd0a77302977d6393ce?d=identicon)[samueljtaylor](/maintainers/samueljtaylor)

---

Top Contributors

[![samyrataylor](https://avatars.githubusercontent.com/u/15961687?v=4)](https://github.com/samyrataylor "samyrataylor (19 commits)")

---

Tags

first-nameformatterlaravellaravel-packagelast-namenamephpphp7

### Embed Badge

![Health badge](/badges/taylornetwork-name-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/taylornetwork-name-formatter/health.svg)](https://phpackages.com/packages/taylornetwork-name-formatter)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[illuminate/pipeline

The Illuminate Pipeline package.

9348.3M267](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10533.5M991](/packages/illuminate-pagination)[illuminate/redis

The Illuminate Redis package.

8314.4M363](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

224.5M132](/packages/illuminate-cookie)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
