PHP code example of watson / nameable

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

    

watson / nameable example snippets


use Watson\Nameable\Nameable;

class User extends Model
{
    protected $casts = [
        'name' => Nameable::class,
    ];
}

use Watson\Nameable\Name;

$name = new Name('Dwight', 'Conrad Watson');

$name = Name::from('Dwight Conrad Watson');

$user = new User(['name' => 'Dwight Watson']);

$user->name->full        // Dwight Watson
$user->name->first       // Dwight
$user->name->last        // Watson
$user->name->familiar    // Dwight W. 
$user->name->abbreviated // D. Watson
$user->name->sorted      // Watson, Dwight
$user->name->initials    // DW

$user = new User(['name' => 'Dwight Watson']);

$user->name->full_possessive        // Dwight Watson's
$user->name->first_possessive       // Dwight's
$user->name->last_possessive        // Watson's
$user->name->abbreviated_possessive // D. Watson's
$user->name->sorted_possessive      // Watson, Dwight's
$user->name->initials_possessive    // DW's

$user = new User(['name' => 'Angus Young']);
$user->name->full_possessive        // Angus Young's
$user->name->first_possessive       // Angus'