├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── config └── config.php ├── database └── migrations │ ├── 2020_01_01_000001_create_contacts_table.php │ └── 2020_01_01_000002_create_contact_relations_table.php ├── phpstan.neon.dist └── src ├── Console └── Commands │ ├── MigrateCommand.php │ ├── PublishCommand.php │ └── RollbackCommand.php ├── Models └── Contact.php ├── Providers └── ContactsServiceProvider.php └── Traits └── HasContacts.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Rinvex Contacts Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | This project adheres to [Semantic Versioning](CONTRIBUTING.md). 6 | 7 | 8 | ## [v5.0.1] - 2020-12-25 9 | - Add support for PHP v8 10 | 11 | ## [v5.0.0] - 2020-12-22 12 | - Upgrade to Laravel v8 13 | - Move custom eloquent model events to module layer from core package layer 14 | - Refactor and tweak Eloquent Events 15 | - Update validation rules 16 | 17 | ## [v4.1.0] - 2020-06-15 18 | - Update validation rules 19 | - Drop using rinvex/laravel-cacheable from core packages for more flexibility 20 | - Caching should be handled on the application layer, not enforced from the core packages 21 | - Drop PHP 7.2 & 7.3 support from travis 22 | 23 | ## [v4.0.6] - 2020-05-30 24 | - Remove default indent size config 25 | - Add strip_tags validation rule to string fields 26 | - Specify events queue 27 | - Explicitly specify relationship attributes 28 | - Add strip_tags validation rule 29 | - Explicitly define relationship name 30 | 31 | ## [v4.0.5] - 2020-04-12 32 | - Fix ServiceProvider registerCommands method compatibility 33 | 34 | ## [v4.0.4] - 2020-04-09 35 | - Tweak artisan command registration 36 | - Reverse commit "Convert database int fields into bigInteger" 37 | - Refactor publish command and allow multiple resource values 38 | 39 | ## [v4.0.3] - 2020-04-04 40 | - Fix namespace issue 41 | 42 | ## [v4.0.2] - 2020-04-04 43 | - Enforce consistent artisan command tag namespacing 44 | - Enforce consistent package namespace 45 | - Drop laravel/helpers usage as it's no longer used 46 | 47 | ## [v4.0.1] - 2020-03-20 48 | - Convert into bigInteger database fields 49 | - Add shortcut -f (force) for artisan publish commands 50 | - Fix migrations path 51 | 52 | ## [v4.0.0] - 2020-03-15 53 | - Upgrade to Laravel v7.1.x & PHP v7.4.x 54 | 55 | ## [v3.0.3] - 2020-03-13 56 | - Tweak TravisCI config 57 | - Add migrations autoload option to the package 58 | - Tweak service provider `publishesResources` 59 | - Remove indirect composer dependency 60 | - Drop using global helpers 61 | - Update StyleCI config 62 | 63 | ## [v3.0.2] - 2019-12-18 64 | - Fix `migrate:reset` args as it doesn't accept --step 65 | - Create event classes and map them in the model 66 | 67 | ## [v3.0.1] - 2019-09-24 68 | - Add missing laravel/helpers composer package 69 | 70 | ## [v3.0.0] - 2019-09-23 71 | - Upgrade to Laravel v6 and update dependencies 72 | 73 | ## [v2.1.1] - 2019-06-03 74 | - Enforce latest composer package versions 75 | 76 | ## [v2.1.0] - 2019-06-02 77 | - Update composer deps 78 | - Drop PHP 7.1 travis test 79 | - Refactor migrations and artisan commands, and tweak service provider publishes functionality 80 | 81 | ## [v2.0.0] - 2019-03-03 82 | - Rename environment variable QUEUE_DRIVER to QUEUE_CONNECTION 83 | - Require PHP 7.2 & Laravel 5.8 84 | - Apply PHPUnit 8 updates 85 | - Tweak and simplify FormRequest validations 86 | 87 | ## [v1.0.2] - 2018-12-22 88 | - Update composer dependencies 89 | - Add PHP 7.3 support to travis 90 | 91 | ## [v1.0.1] - 2018-10-05 92 | - Fix wrong composer package version constraints 93 | 94 | ## [v1.0.0] - 2018-10-01 95 | - Enforce Consistency 96 | - Support Laravel 5.7+ 97 | - Rename package to rinvex/laravel-contacts 98 | 99 | ## [v0.0.2] - 2018-09-22 100 | - Update travis php versions 101 | - Define polymorphic relationship parameters explicitly 102 | - Require missing composer packages and tweak phone validation rule 103 | - Require composer package rinvex/languages 104 | - Simplify contact fields 105 | - Require full name contact field 106 | - Enforce consistency 107 | - Add national_id field and soft deletes 108 | - Update contact fields 109 | - Tweak validation rules 110 | - Drop StyleCI multi-language support (paid feature now!) 111 | - Update composer dependencies 112 | - Split full_name into given_name and family_name fields 113 | - Add organization field for contacts 114 | - Drop social fields from core package 115 | - Prepare and tweak testing configuration 116 | - Highlight variables in strings explicitly 117 | - Update StyleCI options 118 | - Update PHPUnit options 119 | - Add contact model factory 120 | 121 | ## v0.0.1 - 2018-02-18 122 | - Tag first release 123 | 124 | [v5.0.1]: https://github.com/rinvex/laravel-contacts/compare/v5.0.0...v5.0.1 125 | [v5.0.0]: https://github.com/rinvex/laravel-contacts/compare/v4.1.0...v5.0.0 126 | [v4.1.0]: https://github.com/rinvex/laravel-contacts/compare/v4.0.6...v4.1.0 127 | [v4.0.6]: https://github.com/rinvex/laravel-contacts/compare/v4.0.5...v4.0.6 128 | [v4.0.5]: https://github.com/rinvex/laravel-contacts/compare/v4.0.4...v4.0.5 129 | [v4.0.4]: https://github.com/rinvex/laravel-contacts/compare/v4.0.3...v4.0.4 130 | [v4.0.3]: https://github.com/rinvex/laravel-contacts/compare/v4.0.2...v4.0.3 131 | [v4.0.2]: https://github.com/rinvex/laravel-contacts/compare/v4.0.1...v4.0.2 132 | [v4.0.1]: https://github.com/rinvex/laravel-contacts/compare/v4.0.0...v4.0.1 133 | [v4.0.0]: https://github.com/rinvex/laravel-contacts/compare/v3.0.3...v4.0.0 134 | [v3.0.3]: https://github.com/rinvex/laravel-contacts/compare/v3.0.2...v3.0.3 135 | [v3.0.2]: https://github.com/rinvex/laravel-contacts/compare/v3.0.1...v3.0.2 136 | [v3.0.1]: https://github.com/rinvex/laravel-contacts/compare/v3.0.0...v3.0.1 137 | [v3.0.0]: https://github.com/rinvex/laravel-contacts/compare/v2.1.1...v3.0.0 138 | [v2.1.1]: https://github.com/rinvex/laravel-contacts/compare/v2.1.0...v2.1.1 139 | [v2.1.0]: https://github.com/rinvex/laravel-contacts/compare/v2.0.0...v2.1.0 140 | [v2.0.0]: https://github.com/rinvex/laravel-contacts/compare/v1.0.2...v2.0.0 141 | [v1.0.2]: https://github.com/rinvex/laravel-contacts/compare/v1.0.1...v1.0.2 142 | [v1.0.1]: https://github.com/rinvex/laravel-contacts/compare/v1.0.0...v1.0.1 143 | [v1.0.0]: https://github.com/rinvex/laravel-contacts/compare/v0.0.2...v1.0.0 144 | [v0.0.2]: https://github.com/rinvex/laravel-contacts/compare/v0.0.1...v0.0.2 145 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [help@rinvex.com](mailto:help@rinvex.com). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guide 2 | 3 | This project adheres to the following standards and practices. 4 | 5 | 6 | ## Versioning 7 | 8 | This project is versioned under the [Semantic Versioning](http://semver.org/) guidelines as much as possible. 9 | 10 | Releases will be numbered with the following format: 11 | 12 | - `..` 13 | - `..` 14 | 15 | And constructed with the following guidelines: 16 | 17 | - Breaking backward compatibility bumps the major and resets the minor and patch. 18 | - New additions without breaking backward compatibility bump the minor and reset the patch. 19 | - Bug fixes and misc changes bump the patch. 20 | 21 | 22 | ## Pull Requests 23 | 24 | The pull request process differs for new features and bugs. 25 | 26 | Pull requests for bugs may be sent without creating any proposal issue. If you believe that you know of a solution for a bug that has been filed, please leave a comment detailing your proposed fix or create a pull request with the fix mentioning that issue id. 27 | 28 | 29 | ## Coding Standards 30 | 31 | This project follows the FIG PHP Standards Recommendations compliant with the [PSR-1: Basic Coding Standard](http://www.php-fig.org/psr/psr-1/), [PSR-2: Coding Style Guide](http://www.php-fig.org/psr/psr-2/) and [PSR-4: Autoloader](http://www.php-fig.org/psr/psr-4/) to ensure a high level of interoperability between shared PHP code. If you notice any compliance oversights, please send a patch via pull request. 32 | 33 | 34 | ## Feature Requests 35 | 36 | If you have a proposal or a feature request, you may create an issue with `[Proposal]` in the title. 37 | 38 | The proposal should also describe the new feature, as well as implementation ideas. The proposal will then be reviewed and either approved or denied. Once a proposal is approved, a pull request may be created implementing the new feature. 39 | 40 | 41 | ## Git Flow 42 | 43 | This project follows [Git-Flow](http://nvie.com/posts/a-successful-git-branching-model/), and as such has `master` (latest stable releases), `develop` (latest WIP development) and X.Y support branches (when there's multiple major versions). 44 | 45 | Accordingly all pull requests MUST be sent to the `develop` branch. 46 | 47 | > **Note:** Pull requests which do not follow these guidelines will be closed without any further notice. 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2021, Rinvex LLC, 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rinvex Contacts 2 | 3 | ⚠️ This package is abandoned and no longer maintained. No replacement package was suggested. ⚠️ 4 | 5 | 👉 If you are interested to step on as the main maintainer of this package, please [reach out to me](https://twitter.com/omranic)! 6 | 7 | --- 8 | 9 | **Rinvex Contacts** is a polymorphic Laravel package, for contact management system. You can add contacts to any eloquent model with ease. 10 | 11 | [![Packagist](https://img.shields.io/packagist/v/rinvex/laravel-contacts.svg?label=Packagist&style=flat-square)](https://packagist.org/packages/rinvex/laravel-contacts) 12 | [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/rinvex/laravel-contacts.svg?label=Scrutinizer&style=flat-square)](https://scrutinizer-ci.com/g/rinvex/laravel-contacts/) 13 | [![Travis](https://img.shields.io/travis/rinvex/laravel-contacts.svg?label=TravisCI&style=flat-square)](https://travis-ci.org/rinvex/laravel-contacts) 14 | [![StyleCI](https://styleci.io/repos/97991812/shield)](https://styleci.io/repos/97991812) 15 | [![License](https://img.shields.io/packagist/l/rinvex/laravel-contacts.svg?label=License&style=flat-square)](https://github.com/rinvex/laravel-contacts/blob/develop/LICENSE) 16 | 17 | 18 | ## Installation 19 | 20 | 1. Install the package via composer: 21 | ```shell 22 | composer require rinvex/laravel-contacts 23 | ``` 24 | 25 | 2. Publish resources (migrations and config files): 26 | ```shell 27 | php artisan rinvex:publish:contacts 28 | ``` 29 | 30 | 3. Execute migrations via the following command: 31 | ```shell 32 | php artisan rinvex:migrate:contacts 33 | ``` 34 | 35 | 4. Done! 36 | 37 | 38 | ## Usage 39 | 40 | To add contacts support to your eloquent models simply use `\Rinvex\Contacts\Traits\HasContacts` trait. 41 | 42 | ### Manage your contacts 43 | 44 | ```php 45 | // Get instance of your model 46 | $user = new \App\Models\User::find(1); 47 | 48 | // Create a new contact 49 | $user->contacts()->create([ 50 | 'given_name' => 'Abdelrahman', 51 | 'family_name' => 'Omran', 52 | 'title' => 'Software Architect', 53 | 'organization' => 'Rinvex', 54 | 'email' => 'me@omranic.com', 55 | 'phone' => '+201228160181', 56 | 'source' => 'website', 57 | 'method' => 'call', 58 | 'country_code' => 'eg', 59 | 'language_code' => 'en', 60 | 'birthday' => '1987-06-18', 61 | 'gender' => 'male', 62 | ]); 63 | 64 | // Create multiple new contacts 65 | $user->contacts()->createMany([ 66 | [...], 67 | [...], 68 | [...], 69 | ]); 70 | 71 | // Find an existing contact 72 | $contact = app('rinvex.contacts.contact')->find(1); 73 | 74 | // Update an existing contact 75 | $contact->update([ 76 | 'email' => 'iOmranic@gmail.com', 77 | ]); 78 | 79 | // Delete contact 80 | $contact->delete(); 81 | 82 | // Alternative way of contact deletion 83 | $user->contacts()->where('id', 123)->first()->delete(); 84 | 85 | // Get relative contacts collection 86 | $user->relatives; 87 | 88 | // Get relative contacts query builder 89 | $user->relatives(); 90 | 91 | // Get back relative contacts collection 92 | $user->backRelatives; 93 | 94 | // Get back relative contacts query builder 95 | $user->backRelatives(); 96 | 97 | // Get attached contacts collection 98 | $user->contacts; 99 | 100 | // Get attached contacts query builder 101 | $user->contacts(); 102 | ``` 103 | 104 | 105 | ## Changelog 106 | 107 | Refer to the [Changelog](CHANGELOG.md) for a full history of the project. 108 | 109 | 110 | ## Support 111 | 112 | The following support channels are available at your fingertips: 113 | 114 | - [Chat on Slack](https://bit.ly/rinvex-slack) 115 | - [Help on Email](mailto:help@rinvex.com) 116 | - [Follow on Twitter](https://twitter.com/rinvex) 117 | 118 | 119 | ## Contributing & Protocols 120 | 121 | Thank you for considering contributing to this project! The contribution guide can be found in [CONTRIBUTING.md](CONTRIBUTING.md). 122 | 123 | Bug reports, feature requests, and pull requests are very welcome. 124 | 125 | - [Versioning](CONTRIBUTING.md#versioning) 126 | - [Pull Requests](CONTRIBUTING.md#pull-requests) 127 | - [Coding Standards](CONTRIBUTING.md#coding-standards) 128 | - [Feature Requests](CONTRIBUTING.md#feature-requests) 129 | - [Git Flow](CONTRIBUTING.md#git-flow) 130 | 131 | 132 | ## Security Vulnerabilities 133 | 134 | If you discover a security vulnerability within this project, please send an e-mail to [help@rinvex.com](help@rinvex.com). All security vulnerabilities will be promptly contacted. 135 | 136 | 137 | ## About Rinvex 138 | 139 | Rinvex is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Alexandria, Egypt since June 2016. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity. 140 | 141 | 142 | ## License 143 | 144 | This software is released under [The MIT License (MIT)](LICENSE). 145 | 146 | (c) 2016-2021 Rinvex LLC, Some rights reserved. 147 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rinvex/laravel-contacts", 3 | "description": "Rinvex Contacts is a polymorphic Laravel package, for contact management system. You can add contacts to any eloquent model with ease.", 4 | "type": "library", 5 | "keywords": [ 6 | "model", 7 | "rinvex", 8 | "contact", 9 | "laravel", 10 | "country", 11 | "primary", 12 | "billing", 13 | "shipping", 14 | "eloquent", 15 | "contacts", 16 | "polymorphic" 17 | ], 18 | "license": "MIT", 19 | "homepage": "https://rinvex.com", 20 | "support": { 21 | "email": "help@rinvex.com", 22 | "issues": "https://github.com/rinvex/laravel-contacts/issues", 23 | "source": "https://github.com/rinvex/laravel-contacts", 24 | "docs": "https://github.com/rinvex/laravel-contacts/blob/master/README.md" 25 | }, 26 | "authors": [ 27 | { 28 | "name": "Rinvex LLC", 29 | "homepage": "https://rinvex.com", 30 | "email": "help@rinvex.com" 31 | }, 32 | { 33 | "name": "Abdelrahman Omran", 34 | "homepage": "https://omranic.com", 35 | "email": "me@omranic.com", 36 | "role": "Project Lead" 37 | }, 38 | { 39 | "name": "The Generous Laravel Community", 40 | "homepage": "https://github.com/rinvex/laravel-contacts/contributors" 41 | } 42 | ], 43 | "require": { 44 | "php": "^7.4.0 || ^8.0.0", 45 | "illuminate/console": "^8.0.0 || ^9.0.0", 46 | "illuminate/database": "^8.0.0 || ^9.0.0", 47 | "illuminate/support": "^8.0.0 || ^9.0.0", 48 | "jackpopp/geodistance": "^1.2.0", 49 | "propaganistas/laravel-phone": "^4.2.0", 50 | "rinvex/countries": "^7.0.0", 51 | "rinvex/languages": "^5.0.0", 52 | "rinvex/laravel-support": "^5.0.0" 53 | }, 54 | "require-dev": { 55 | "codedungeon/phpunit-result-printer": "^0.30.0", 56 | "illuminate/container": "^8.0.0 || ^9.0.0", 57 | "phpunit/phpunit": "^9.5.0" 58 | }, 59 | "autoload": { 60 | "psr-4": { 61 | "Rinvex\\Contacts\\": "src/" 62 | } 63 | }, 64 | "autoload-dev": { 65 | "psr-4": { 66 | "Rinvex\\Contacts\\Tests\\": "tests" 67 | } 68 | }, 69 | "scripts": { 70 | "test": "vendor/bin/phpunit" 71 | }, 72 | "config": { 73 | "sort-packages": true, 74 | "preferred-install": "dist", 75 | "optimize-autoloader": true 76 | }, 77 | "extra": { 78 | "laravel": { 79 | "providers": [ 80 | "Rinvex\\Contacts\\Providers\\ContactsServiceProvider" 81 | ] 82 | } 83 | }, 84 | "minimum-stability": "dev", 85 | "prefer-stable": true 86 | } 87 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | true, 9 | 10 | // Contacts Database Tables 11 | 'tables' => [ 12 | 'contacts' => 'contacts', 13 | 'contact_relations' => 'contact_relations', 14 | ], 15 | 16 | // Contacts Models 17 | 'models' => [ 18 | 'contact' => \Rinvex\Contacts\Models\Contact::class, 19 | ], 20 | 21 | ]; 22 | -------------------------------------------------------------------------------- /database/migrations/2020_01_01_000001_create_contacts_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 15 | $table->morphs('entity'); 16 | $table->string('given_name'); 17 | $table->string('family_name')->nullable(); 18 | $table->string('title')->nullable(); 19 | $table->string('organization')->nullable(); 20 | $table->string('email')->nullable(); 21 | $table->string('phone')->nullable(); 22 | $table->string('fax')->nullable(); 23 | $table->string('country_code', 2)->nullable(); 24 | $table->string('language_code', 2)->nullable(); 25 | $table->date('birthday')->nullable(); 26 | $table->string('gender')->nullable(); 27 | $table->string('national_id_type')->nullable(); 28 | $table->string('national_id')->nullable(); 29 | $table->string('source')->nullable(); 30 | $table->string('method')->nullable(); 31 | $table->text('notes')->nullable(); 32 | $table->timestamps(); 33 | $table->softDeletes(); 34 | }); 35 | } 36 | 37 | public function down() 38 | { 39 | Schema::dropIfExists(config('rinvex.contacts.tables.contacts')); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /database/migrations/2020_01_01_000002_create_contact_relations_table.php: -------------------------------------------------------------------------------- 1 | integer('contact_id')->unsigned(); 16 | $table->integer('related_id')->unsigned(); 17 | $table->string('relation'); 18 | $table->timestamps(); 19 | 20 | // Indexes 21 | $table->primary(['contact_id', 'related_id']); 22 | $table->foreign('contact_id')->references('id')->on(config('rinvex.contacts.tables.contacts')) 23 | ->onDelete('cascade')->onUpdate('cascade'); 24 | $table->foreign('related_id')->references('id')->on(config('rinvex.contacts.tables.contacts')) 25 | ->onDelete('cascade')->onUpdate('cascade'); 26 | }); 27 | } 28 | 29 | public function down() 30 | { 31 | Schema::dropIfExists(config('rinvex.contacts.tables.contact_relations')); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | includes: 2 | - ./vendor/nunomaduro/larastan/extension.neon 3 | parameters: 4 | level: 5 5 | paths: 6 | - src 7 | -------------------------------------------------------------------------------- /src/Console/Commands/MigrateCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | $path = config('rinvex.contacts.autoload_migrations') ? 35 | 'vendor/rinvex/laravel-contacts/database/migrations' : 36 | 'database/migrations/rinvex/laravel-contacts'; 37 | 38 | if (file_exists($path)) { 39 | $this->call('migrate', [ 40 | '--step' => true, 41 | '--path' => $path, 42 | '--force' => $this->option('force'), 43 | ]); 44 | } else { 45 | $this->warn('No migrations found! Consider publish them first: php artisan rinvex:publish:contacts'); 46 | } 47 | 48 | $this->line(''); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Console/Commands/PublishCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | collect($this->option('resource') ?: ['config', 'migrations'])->each(function ($resource) { 35 | $this->call('vendor:publish', ['--tag' => "rinvex/contacts::{$resource}", '--force' => $this->option('force')]); 36 | }); 37 | 38 | $this->line(''); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Console/Commands/RollbackCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | $path = config('rinvex.contacts.autoload_migrations') ? 35 | 'vendor/rinvex/laravel-contacts/database/migrations' : 36 | 'database/migrations/rinvex/laravel-contacts'; 37 | 38 | if (file_exists($path)) { 39 | $this->call('migrate:reset', [ 40 | '--path' => $path, 41 | '--force' => $this->option('force'), 42 | ]); 43 | } else { 44 | $this->warn('No migrations found! Consider publish them first: php artisan rinvex:publish:contacts'); 45 | } 46 | 47 | $this->line(''); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Models/Contact.php: -------------------------------------------------------------------------------- 1 | 'integer', 106 | 'entity_type' => 'string', 107 | 'given_name' => 'string', 108 | 'family_name' => 'string', 109 | 'title' => 'string', 110 | 'organization' => 'string', 111 | 'email' => 'string', 112 | 'phone' => 'string', 113 | 'fax' => 'string', 114 | 'country_code' => 'string', 115 | 'language_code' => 'string', 116 | 'birthday' => 'string', 117 | 'gender' => 'string', 118 | 'national_id_type' => 'string', 119 | 'national_id' => 'string', 120 | 'source' => 'string', 121 | 'method' => 'string', 122 | 'notes' => 'string', 123 | 'deleted_at' => 'datetime', 124 | ]; 125 | 126 | /** 127 | * {@inheritdoc} 128 | */ 129 | protected $observables = [ 130 | 'validating', 131 | 'validated', 132 | ]; 133 | 134 | /** 135 | * The default rules that the model will validate against. 136 | * 137 | * @var array 138 | */ 139 | protected $rules = [ 140 | 'entity_id' => 'required|integer', 141 | 'entity_type' => 'required|string|strip_tags|max:150', 142 | 'given_name' => 'required|string|strip_tags|max:150', 143 | 'family_name' => 'nullable|string|strip_tags|max:150', 144 | 'title' => 'nullable|string|strip_tags|max:150', 145 | 'organization' => 'nullable|string|strip_tags|max:150', 146 | 'email' => 'required|email|min:3|max:128', 147 | 'phone' => 'nullable|phone:AUTO', 148 | 'fax' => 'nullable|string|strip_tags|max:150', 149 | 'country_code' => 'nullable|alpha|size:2|country', 150 | 'language_code' => 'nullable|alpha|size:2|language', 151 | 'birthday' => 'nullable|date_format:Y-m-d', 152 | 'gender' => 'nullable|in:male,female', 153 | 'national_id_type' => 'nullable|in:identification,passport,other', 154 | 'national_id' => 'nullable|string|strip_tags|max:150', 155 | 'source' => 'nullable|string|strip_tags|max:150', 156 | 'method' => 'nullable|string|strip_tags|max:150', 157 | 'notes' => 'nullable|string|strip_tags|max:32768', 158 | ]; 159 | 160 | /** 161 | * Whether the model should throw a 162 | * ValidationException if it fails validation. 163 | * 164 | * @var bool 165 | */ 166 | protected $throwValidationExceptions = true; 167 | 168 | /** 169 | * Create a new Eloquent model instance. 170 | * 171 | * @param array $attributes 172 | */ 173 | public function __construct(array $attributes = []) 174 | { 175 | parent::__construct($attributes); 176 | 177 | $this->setTable(config('rinvex.contacts.tables.contacts')); 178 | } 179 | 180 | /** 181 | * Get the owner model of the contact. 182 | * 183 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 184 | */ 185 | public function entity(): MorphTo 186 | { 187 | return $this->morphTo('entity', 'entity_type', 'entity_id', 'id'); 188 | } 189 | 190 | /** 191 | * Enforce clean sources. 192 | * 193 | * @param string $value 194 | * 195 | * @return void 196 | */ 197 | public function setSourceAttribute($value): void 198 | { 199 | $this->attributes['source'] = Str::slug($value); 200 | } 201 | 202 | /** 203 | * Enforce clean methods. 204 | * 205 | * @param string $value 206 | * 207 | * @return void 208 | */ 209 | public function setMethodAttribute($value): void 210 | { 211 | $this->attributes['method'] = Str::slug($value); 212 | } 213 | 214 | /** 215 | * Scope contacts by the given country. 216 | * 217 | * @param \Illuminate\Database\Eloquent\Builder $builder 218 | * @param string $countryCode 219 | * 220 | * @return \Illuminate\Database\Eloquent\Builder 221 | */ 222 | public function scopeCountry(Builder $builder, string $countryCode): Builder 223 | { 224 | return $builder->where('country_code', $countryCode); 225 | } 226 | 227 | /** 228 | * Scope contacts by the given language. 229 | * 230 | * @param \Illuminate\Database\Eloquent\Builder $builder 231 | * @param string $languageCode 232 | * 233 | * @return \Illuminate\Database\Eloquent\Builder 234 | */ 235 | public function scopeLanguage(Builder $builder, string $languageCode): Builder 236 | { 237 | return $builder->where('language_code', $languageCode); 238 | } 239 | 240 | /** 241 | * Scope contacts by the given source. 242 | * 243 | * @param \Illuminate\Database\Eloquent\Builder $builder 244 | * @param string $source 245 | * 246 | * @return \Illuminate\Database\Eloquent\Builder 247 | */ 248 | public function scopeSource(Builder $builder, string $source): Builder 249 | { 250 | return $builder->where('source', $source); 251 | } 252 | 253 | /** 254 | * Scope contacts by the given method. 255 | * 256 | * @param \Illuminate\Database\Eloquent\Builder $builder 257 | * @param string $method 258 | * 259 | * @return \Illuminate\Database\Eloquent\Builder 260 | */ 261 | public function scopeMethod(Builder $builder, string $method): Builder 262 | { 263 | return $builder->where('method', $method); 264 | } 265 | 266 | /** 267 | * Get full name attribute. 268 | * 269 | * @return string 270 | */ 271 | public function getFullNameAttribute(): string 272 | { 273 | return implode(' ', [$this->given_name, $this->family_name]); 274 | } 275 | 276 | /** 277 | * A contact may have multiple related contacts. 278 | * 279 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany 280 | */ 281 | public function relatives(): BelongsToMany 282 | { 283 | return $this->belongsToMany(self::class, config('rinvex.contacts.tables.contact_relations'), 'contact_id', 'related_id', 'id', 'id', 'relatives') 284 | ->withPivot(['relation'])->withTimestamps(); 285 | } 286 | 287 | /** 288 | * A contact may be related to multiple contacts. 289 | * 290 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany 291 | */ 292 | public function backRelatives(): BelongsToMany 293 | { 294 | return $this->belongsToMany(self::class, config('rinvex.contacts.tables.contact_relations'), 'related_id', 'contact_id', 'id', 'id', 'backRelatives') 295 | ->withPivot(['relation'])->withTimestamps(); 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /src/Providers/ContactsServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'command.rinvex.contacts.migrate', 25 | PublishCommand::class => 'command.rinvex.contacts.publish', 26 | RollbackCommand::class => 'command.rinvex.contacts.rollback', 27 | ]; 28 | 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | public function register() 33 | { 34 | // Merge config 35 | $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.contacts'); 36 | 37 | // Bind eloquent models to IoC container 38 | $this->app->singleton('rinvex.contacts.contact', $contactModel = $this->app['config']['rinvex.contacts.models.contact']); 39 | $contactModel === Contact::class || $this->app->alias('rinvex.contacts.contact', Contact::class); 40 | 41 | // Register console commands 42 | $this->registerCommands($this->commands); 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function boot() 49 | { 50 | // Publish Resources 51 | $this->publishesConfig('rinvex/laravel-contacts'); 52 | $this->publishesMigrations('rinvex/laravel-contacts'); 53 | ! $this->autoloadMigrations('rinvex/laravel-contacts') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Traits/HasContacts.php: -------------------------------------------------------------------------------- 1 | contacts()->delete(); 42 | }); 43 | } 44 | 45 | /** 46 | * Get all attached contacts to the model. 47 | * 48 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 49 | */ 50 | public function contacts(): MorphMany 51 | { 52 | return $this->morphMany(config('rinvex.contacts.models.contact'), 'entity'); 53 | } 54 | } 55 | --------------------------------------------------------------------------------