PHP code example of druc / person-name

1. Go to this page and download the library: Download druc/person-name 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/ */

    

druc / person-name example snippets



// Create instance
$name = PersonName::make('Constantin Druc');

// Get full name
$name->full; // Constantin Druc

// Get first name
$name->first; // Constantin

// Get last name
$name->last; // Druc

// Get name initials
$name->initials; // CD

// Get familiar name
$name->familiar; // Constantin D.

// Get abbreviated name
$name->abbreviated; // C. Druc

// Get sorted name
$name->sorted; // Druc, Constantin

// Get mentionable name
$name->mentionable; // constantind

// Get possessive name
$name->possessive; // Constantin Druc's


// in App/User.php

public function getNameAttribute() 
{
    return PersonName::make($this->attributes['name']);
}

// Somewhere in your app
$user->name->familiar;