Download the PHP package kwidoo/laravel-contacts without Composer

On this page you can find all versions of the php package kwidoo/laravel-contacts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-contacts

Latest Version on Packagist Total Downloads GitHub Actions

Laravel Contacts

A Laravel package that provides a robust, event-sourced approach to managing multiple contact types (e.g., phone, email) for your Eloquent models. It offers features such as:

Table of Contents

  1. Installation
  2. Configuration
  3. Migrations
  4. Usage
    • Adding the HasContacts Trait
    • Creating Contacts
    • Listing Contacts
    • Verifying Contacts
    • Deleting and Restoring Contacts
    • Setting a Primary Contact
  5. Event Sourcing
  6. Advantages
  7. Additional Notes

Installation

  1. Require this package in your Laravel application:

  2. This package also relies on Spatie's Laravel Event Sourcing under the hood. If you have not already installed and configured Spatie's event sourcing package, you should do so.

Configuration

  1. Publish Config:

    This will create a config/contacts.php file. Inside you will find the following key aspects:

    • model – The contact Eloquent model class (default: Kwidoo\Contacts\Models\Contact).
    • table – The database table for storing contacts (default: contacts).
    • uuid – Whether to use UUIDs as the primary key (boolean).
    • verifiers – A list of verifiers for different contact types (email, phone, etc.).
    • token – Configuration for token generation, including token length, TTL, and the token model/table.
  2. Bind Twilio or Other Services: If you plan to use phone verification (PhoneVerifier), make sure you bind or configure any external SMS provider like Twilio. The example implementation references a Kwidoo\MultiAuth\Services\TwilioService. Adapt this service to your application’s needs.

  3. Event Sourcing: This package automatically merges its required projector (\Kwidoo\Contacts\Projectors\ContactProjector::class) into your event-sourcing.projectors config. Make sure Spatie Event Sourcing is installed and configured appropriately.

Migrations

After installing, run:

This will publish and run the necessary migrations for storing contacts and tokens in your database.


Usage

Adding the HasContacts Trait

Any model (User, Company, etc.) that you wish to associate contacts with should implement Kwidoo\Contacts\Contracts\Contactable and use the Kwidoo\Contacts\Traits\HasContacts trait.

Example on a User model:

Important: The HasContacts trait adds a polymorphic relationship contacts() and also provides a getPrimaryContactAttribute accessor.

Creating Contacts

You can create a contact through the provided controller or directly through the ContactService.

Via Controller and Routes

The package registers RESTful routes for contacts. You can do a POST request to contacts (by default at /contacts) with the request body containing:

The validation ensures the type matches one of the configured verifiers (e.g., email, phone), and the value is unique for that model.

If successful, the route redirects to contacts.show (by default /contacts/{contact}).

Via ContactService

If you prefer direct usage in your code:

Listing Contacts

Using the built-in controller route:

Or directly from your model:

Verifying Contacts

Contacts can be verified via a token-based approach:

  1. Initiate Verification:

    This calls VerificationController@sendVerification. It triggers a token generation and sends out the verification (via email or SMS, depending on the contact type).

  2. Complete Verification:

    This calls VerificationController@verify. If the token is valid, the ContactVerified event is recorded, and the contact is marked as verified.

Deleting and Restoring Contacts

Setting a Primary Contact

By default, the first contact you create becomes the primary contact. You can change the primary contact via:

This calls ContactController@markAsPrimary, leveraging the ContactAggregateRoot to update the primary contact.


Event Sourcing

This package uses Spatie's Event Sourcing to record:

The ContactProjector listens for these events and updates the read models (the contacts table). If you need to replay or track changes, you can use event sourcing commands (e.g., php artisan event-sourcing:replay) to rebuild state.


Advantages

  1. Event-Sourced: Full audit trail and ability to replay contact-related events.
  2. Multiple Contact Types: Phone, email, or any custom type your application requires.
  3. Token-Based Verification: Supports both email and phone verifications via token-based, OTP-like flows.
  4. Soft Delete + Restore: Helps maintain history and preserves referential integrity.
  5. Primary Contact Management: Ensures only one primary contact per model, with easy swaps.
  6. Configurable UUIDs: Toggle between numeric IDs or UUIDs for your contacts.
  7. Extensibility: Swappable verifiers, token generation, and external notification services (e.g., Twilio for SMS).
  8. Polymorphic: Manage contacts for any Eloquent model (User, Company, etc.).

Additional Notes

Feel free to open issues or submit pull requests to enhance functionality or documentation. Enjoy managing your contacts in a more robust, scalable, and auditable fashion!


All versions of laravel-contacts with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
spatie/laravel-event-sourcing Version ^7.5
kwidoo/sms-verification Version ^1.1.1
illuminate/support Version ^12.0
illuminate/database Version ^12.0
prettus/l5-repository Version ^2.10.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kwidoo/laravel-contacts contains the following files

Loading the files please wait ...