yaroslawww/laravel-eloquent-user-fullname

Simple helper, to quickly add user fields: First Name, Middle Name, Last Name, username, Name, Full Name

0.3.0 2019-07-07 12:32 UTC

This package is auto-updated.

Last update: 2024-11-08 01:07:14 UTC


README

Software License Build Status StyleCI Quality Score Code Coverage PHP Version Packagist Version

Simple helper, to quickly add user "name" fields: First Name, Middle Name, Last Name, Name, Full Name. You can quickly add a library and do not write additional tests as the library covers them. Or you can just copy Trait :)

Installation

You can install the package via composer:

composer require yaroslawww/laravel-eloquent-user-fullname

Usage

use Angecode\LaravelFullName\Models\Traits\HasFullName;
...

class User extends Authenticatable
{
     use HasFullName;
     ...
}
$user = User::first();

$user->first_name   // Yaroslav
$user->middle_name   // Dev
$user->last_name   // Georgitsa
$user->name   // Yaroslav Georgitsa
$user->full_name   // Yaroslav Dev Georgitsa

Publish

There added stub migration file to add required fields

php artisan vendor:publish --provider="Angecode\LaravelFullName\FullNameServiceProvider" --tag="migrations"

Helpers

Package provide helper functions

$result = StrHelper::implodeFiltered([
    'foo',
    null,
    'bar',
    ''
]);

echo $result; // "foo bar"

$result = StrHelper::implodeFiltered([
    'foo',
    'test',
    'bar',
    'test',
], '|', function ($item){
    return $item == 'test';
});

echo $result; // "test|test"

Testing

composer test

Security

If you discover any security related issues, please email yaroslav.georgitsa@gmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.