cleaniquecoders / profile
Common Profile Information
Fund package maintenance!
cleaniquecoders
Installs: 2 971
Dependents: 4
Suggesters: 0
Security: 0
Stars: 12
Watchers: 2
Forks: 3
Open Issues: 2
Requires
- php: ^8.1 | ^8.2 | ^8.3
- cleaniquecoders/blueprint-macro: ^5.0
- illuminate/auth: ^9.0 | ^10.0 | ^11.0
- illuminate/support: ^9.0 | ^10.0 | ^11.0
Requires (Dev)
- laravel/pint: ^1.6
- orchestra/testbench: 7.*|8.*
- pestphp/pest: ^2.0
- phpstan/phpstan-phpunit: ^1.2
- dev-master
- v5.0.0
- v4.1.1
- 4.1.0
- 4.0.0
- v3.1.3
- v3.1.2
- 3.1.1
- 3.1.0
- v3.0.0
- v2.0.0
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-5
- dev-dependabot/github_actions/actions/checkout-4
This package is auto-updated.
Last update: 2024-04-21 03:47:59 UTC
README
Profile is a package to store basic information - addresses, phone numbers, emails, and websites using Polymorph approach.
Installation
- In order to install Profile in your Laravel project:
$ composer require cleaniquecoders/profile
- Then in your
config/app.php
add the following to theproviders
key:
\CleaniqueCoders\Profile\ProfileServiceProvider::class,
Publish factory files:
$ php artisan vendor:publish --tag=profile-factories
Publish migrations files:
$ php artisan vendor:publish --tag=profile-migrations
Publish seed files:
$ php artisan vendor:publish --tag=profile-seeds
Then run:
$ php artisan migrate
Then seed the Country and Phone Types data with:
$ php artisan profile:seed
Configuration
Now you are able to configure your own models and type name. See config/profile.php
.
You may want to define your own seeders for profile:seed
in config/profile.php
.
Available Polymorph Traits
User Cases:
- A company has addresses, phone numbers, emails and websites.
- An employee has addresses, phone numbers, emails and websites.
This lead us to use Polymorph to tackle the issue of similarity in data stored.
Setup
Available traits for polymorph:
CleaniqueCoders\Profile\Traits\Morphs\Addressable
CleaniqueCoders\Profile\Traits\Morphs\Emailable
CleaniqueCoders\Profile\Traits\Morphs\Phoneable
CleaniqueCoders\Profile\Traits\Morphs\Websiteable
CleaniqueCoders\Profile\Traits\Morphs\Bankable
For most common setup for entity is to use HasProfile
trait.
HasProfile
trait consist of:
CleaniqueCoders\Profile\Traits\Morphs\Addressable
CleaniqueCoders\Profile\Traits\Morphs\Emailable
CleaniqueCoders\Profile\Traits\Morphs\Phoneable
CleaniqueCoders\Profile\Traits\Morphs\Websiteable
namespace App; use CleaniqueCoders\Profile\Traits\HasProfile; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use HasProfile; }
Usage
Create a record for each profile
$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
$user->addresses; $user->emails; $user->phones; $user->websites; $user->banks;
License
This package is open-sourced software licensed under the MIT license.