PHP code example of taylornetwork / name-formatter

1. Go to this page and download the library: Download taylornetwork/name-formatter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

taylornetwork / name-formatter example snippets


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

class Customer extends Model
{
	use FormatsFullName;

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

echo $customer->fullName;

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');
	}
}
 bash
$ php artisan vendor:publish
 php
'John Doe'
 php
$model->first_name = 'John';
$model->last_name = 'Doe';

$formatter = new TaylorNetwork\Formatters\Name\Formatter($model);
 php
$formatter->style('f L')->format();

// Returns

'J Doe'
 php
$formatter->style('l, F')->format();

// Returns

'D, John'
 php
$formatter->style('fl')->format();

// Returns

'JD'
 php
$formatter->style('F_L')->format();

// Returns

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

// Returns

'JJJJohn DDDDoe'