2017 © Pedro Peláez
 

library profile

Common Profile Information

image

cleaniquecoders/profile

Common Profile Information

  • Monday, June 18, 2018
  • by nasrulhazim.m
  • Repository
  • 2 Watchers
  • 7 Stars
  • 1,238 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 93 % Grown

The README.md

Profile

Profile is a package to store basic information - addresses, phone numbers, emails, and websites using Polymorph approach., (*1)

Latest Stable Version Total Downloads Scrutinizer Code Quality License, (*2)

Installation

Install Profile package by running in your terminal:, (*3)

composer require cleaniquecoders/profile

Publish migrations files:, (*4)

php artisan vendor:publish --tag=profile-migrations

Then run:, (*5)

php artisan migrate

Then run default seeders:, (*6)

php artisan profile:seed

Configuration

Now you are able to configure your own models and type name. See config/profile.php., (*7)

You may want to define your own seeders for profile:seed in config/profile.php., (*8)

Available Polymorph Traits

User Cases:, (*9)

  1. A company has addresses, phone numbers, emails and websites.
  2. An employee has addresses, phone numbers, emails and websites.

This lead us to use Polymorph to tackle the issue of similarity in data stored., (*10)

Setup

Available traits for polymorph:, (*11)

  1. CleaniqueCoders\Profile\Concerns\Addressable
  2. CleaniqueCoders\Profile\Concerns\Emailable
  3. CleaniqueCoders\Profile\Concerns\Phoneable
  4. CleaniqueCoders\Profile\Concerns\Websiteable
  5. CleaniqueCoders\Profile\Concerns\Bankable

For most common setup for entity is to use HasProfile trait., (*12)

HasProfile trait consist of:, (*13)

  1. CleaniqueCoders\Profile\Concerns\Addressable
  2. CleaniqueCoders\Profile\Concerns\Emailable
  3. CleaniqueCoders\Profile\Concerns\Phoneable
  4. CleaniqueCoders\Profile\Concerns\Websiteable

namespace App; use CleaniqueCoders\Profile\Concerns\HasProfile; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use HasProfile; }

Usage

Create a record for each profile, (*14)

$user->addresses()->create([
 'primary' => '9 miles, Sungei Way',
 'secondary' => 'P.O.Box 6503, Seri Setia',
 'city' => 'Petaling Jaya',
 'postcode' => '46150',
 'state' => 'Selangor',
 'country_id' => config('profile.providers.country.model')::name('Malaysia')->first()->id
]);
$user->phones()->create([
    'phone_number'  => '+6089259167',
    'is_default'    => true,
    'phone_type_id' => PhoneType::HOME,
]);
$user->phones()->create([
    'phone_number'  => '+60191234567',
    'is_default'    => true,
    'phone_type_id' => PhoneType::MOBILE,
]);
$user->phones()->create([
    'phone_number'  => '+60380001000',
    'is_default'    => true,
    'phone_type_id' => PhoneType::OFFICE,
]);
$user->phones()->create([
    'phone_number'  => '+60380001000',
    'is_default'    => true,
    'phone_type_id' => PhoneType::OTHER,
]);
$user->phones()->create([
    'phone_number'  => '+60380001001',
    'is_default'    => true,
    'phone_type_id' => PhoneType::FAX,
]);

// you can futher query using local scopes in phone models.
// get the first home phone number
$user->phones()->home()->first();
// get all the mobile phone numbers
$user->phones()->mobile()->get();
$user->emails()->create([...]);
$user->websites()->create([...]);
$user->bankable()->create([...]);

Get all records, (*15)

$user->addresses;
$user->emails;
$user->phones;
$user->websites;
$user->banks;

License

This package is open-sourced software licensed under the MIT license., (*16)

The Versions

24/12 2017

v1.0.2

1.0.2.0

Common Profile Information

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nasrul Hazim

24/12 2017

v1.0.1

1.0.1.0

Common Profile Information

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nasrul Hazim

24/12 2017

v1.0.0

1.0.0.0

Common Profile Information

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nasrul Hazim