trexology/contactable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

trexology/contactable

Composer 安装命令:

composer require trexology/contactable

包简介

Allows users to have multiple e-mail addresses and phone numbers, and log in with them, on Laravel

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Contactable

A Laravel 5.2+ package designed to enhance Eloquent users (or any other model) with relations to multiple e-mail addresses and addresses, additionally allowing users to login with any of the above.

composer require trexology/contactable

And then include the service provider within app/config/app.php. (not required for laravel 5.5+)

'providers' => [
    Trexology\Contactable\PointableServiceProvider::class
];

At last you need to publish and run the migration.

php artisan vendor:publish --provider="Trexology\Contactable\Providers\ContactableServiceProvider" && php artisan migrate

This will add addresses, email_addresses and phone_numbers tables to your database.

Remove the email column from your create_users_table table migration, if applicable.

Usage

For any models you would like to have their own addresses or e-mail addresses, add the appropriate trait:

use Trexology\Contactable\Traits\Addressable;
use Trexology\Contactable\Traits\Phonable;
use Trexology\Contactable\Traits\Emailable;

class User extends Authenticatable implements
{
    use Addressable, Phonable, Emailable;

…or use the Contactable trait to quickly add addresses, phones and e-mails:

use Trexology\Contactable\Traits\Contactable;

class User extends Authenticatable implements
{
    use Contactable;

The above traits simply add the appropriate relationships to your model. Now, you may query the relationships using Eloquent as you normally would.

E-mail addresses are accessed via the “emails()” method (a MorphMany relationship):

<?php

// Add an e-mail address to a new model
$model = new Model;
$model->emails()->save(new \Trexology\Contactable\EmailAddress(['address' => 'zero@example.com']));

// Add multiple e-mail addresses to a pre-existing model
$model = Model::find(1);
$model->emails()->saveMany([
    new \Trexology\Contactable\EmailAddress(['address' => 'one@example.com']),
    new \Trexology\Contactable\EmailAddress(['address' => 'two@example.com']),
]);


// Query records which have at least two e-mail addresses
Model::has('emails', '>=', 2)->get();

// Query records which have a specific e-mail address
$address = 'three@example.com';
Model::whereHas('emails', function ($query) use ($address) {
    $query->where('address', '=', $address);
});

Phone are accessed via the “phones()” method (a MorphMany relationship):

<?php

// Add a phone number to a new model
$model = new Model;
$model->phones()->save(new \Trexology\Contactable\PhoneNumber(['number' => '123 4567']));

// Add multiple addresses to a pre-existing model
$model = Model::find(1);
$model->phones()->saveMany([
    new \Trexology\Contactable\PhoneNumber(['number' => '(234) 567-8900']),
    new \Trexology\Contactable\PhoneNumber(['number' => '2222222']),
]);

// Query records which have at least two addresses
Model::has('phones', '>=', 2)->get();

// Query records which have a specific phone number
$number = '(000) 011-0000';
Model::whereHas('phones', function ($query) use ($number) {
    $query->where('raw_number', '=', preg_replace("/[^0-9]/", '', $number)); // query only the numbers
});

Address are accessed via the addresses()” method (a MorphMany relationship):

<?php

// Add an address to a new model
$model = new Model;
$model->addresses()->save(new \Trexology\Contactable\Address(
    [
      'block' => '923',
      'unit' => '#08-110',
      'street' => 'Laravel Road 3',
      'postal_code' => '827923', // or zip or zip_code
      'country' => 'singapore',
      'country_code' => 'sg',
      'lat' => '-7.7871130',
      'long' => '39.7667430',
    ]
  ));

// Add multiple addresses to a pre-existing model
$model = Model::find(1);

$model->addresses()->saveMany([
    new \Trexology\Contactable\Address(
      [
        'block' => '923',
        'unit' => '#08-110',
        'street' => 'Laravel Road 3',
        'postal_code' => '827923', // or zip or zip_code
        'country' => 'singapore',
        'country_code' => 'sg',
        'lat' => '-7.7871130',
        'long' => '39.7667430',
      ]
    ),
    new \Trexology\Contactable\Address(
      [
        'block' => '782',
        'unit' => '#09-36',
        'street' => 'Laravel Road 3',
        'postal_code' => '876782', // or zip or zip_code
        'country' => 'singapore',
        'country_code' => 'sg',
        'lat' => '33.0691390',
        'long' => '44.0820410',
      ]
    ),
]);

// Query records which have at least two addresses
Model::has('addresses', '>=', 2)->get();

// Query records which have a specific street name
$street_name = '%Laravel Road 2%';
Model::whereHas('addresses', function ($query) use ($street_name) {
    $query->where('street', 'LIKE', $street_name);
});

trexology/contactable 适用场景与选型建议

trexology/contactable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 362 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 trexology/contactable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 trexology/contactable 我们能提供哪些服务?
定制开发 / 二次开发

基于 trexology/contactable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 362
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2018-12-09