LaravelPackages.net
Acme Inc.
Toggle sidebar
developerabod/laravel-contact-exporter

A Laravel package to efficiently manage and export contacts as vCard (.vcf) files.

6
2
1.0.0
About developerabod/laravel-contact-exporter

developerabod/laravel-contact-exporter is a Laravel package for a laravel package to efficiently manage and export contacts as vcard (.vcf) files.. It currently has 2 GitHub stars and 6 downloads on Packagist (latest version 1.0.0). Install it with composer require developerabod/laravel-contact-exporter. Discover more Laravel packages by developerabod or browse all Laravel packages to compare alternatives.

Last updated

πŸ“‡ Laravel Contact Exporter

Laravel Contact Exporter
**A Laravel package to export database contacts as vCard (`.vcf`) files β€” clean, professional, and effortless.**

PHP Laravel License: MIT

composer require developerabod/laravel-contact-exporter

✨ Features

  • πŸ“± Export contacts as a .vcf file ready to import on any smartphone
  • 🌍 Full Arabic name support with UTF-8 charset
  • πŸš€ Chunked database reading β€” memory-safe with millions of records
  • πŸ”Œ Works with both Eloquent Models and DB::table queries
  • 🧩 Clean Fluent API β€” intuitive and expressive
  • βš™οΈ Fully configurable without touching the package source code

πŸ“¦ Installation

Step 1 β€” Install via Composer

composer require developerabod/laravel-contact-exporter

Step 2 β€” Publish the Config File

php artisan vendor:publish --tag=vcard-exporter-config

This creates the file: config/vcard-exporter.php


βš™οΈ Configuration

Open config/vcard-exporter.php and map each config key to the actual column name in your database table:

return [

    'table' => 'users', // Your database table name

    'columns' => [
        'first_name'   => 'first_name',  // The column name in your table
        'last_name'    => null,           // null = disabled by default
        'middle_name'  => null,

        'phone_mobile' => 'phone',        // Primary mobile number β€” required
        'phone_work'   => null,         // Optional work phone number (disabled by default)
        'phone_home'   => null,        // Optional home phone number (disabled by default)

        'email'        => null,           // null = disabled by default
    ],

    'filename'         => 'contacts',     // Base name of the exported file (e.g. contacts.csv)
    'append_count'     => true, // If true: appends total contact count to filename, Example:contacts_250.vcf
    'append_date'      => false, // If true: appends export date to filename Example: contacts_2026-02-22.vcf
    'skip_empty_phone' => true, 
    'normalize_phone'  => true,
    'charset_utf8'     => true, // Enables UTF-8 encoding to support arabic
    'chunk_size'       => 500,  // Chunk size for optimized processing

];

Note: last_name and email are disabled by default. Enable them at runtime using withLastName() and withEmail() on the VCard facade β€” no config changes needed.


πŸš€ Usage

Simplest Case β€” Relies entirely on config

use VCard;

public function export()
{
    return VCard::download();
    // Output: contacts_250.vcf
}

With Last Name

return VCard::withLastName()->download();

With Email

return VCard::withEmail()->download();

With Both Last Name and Email

return VCard::withLastName()->withEmail()->download();

Different Table (overrides config)

return VCard::from('users')->download();

Override Column Mapping (without changing config)

return VCard::map([
    'first_name'   => 'name',
    'phone_mobile' => 'mobile_number',
])->download();

With WHERE Conditions

return VCard::where(['active' => 1])->download();

// Multiple conditions
return VCard::where(['active' => 1, 'country' => 'SA'])->download();

Note: where() only works when using from(). Do not combine it with fromQuery().


From an Eloquent Model

// All records
return VCard::fromQuery(Contact::query())->download();

// Using an existing scope on the model
return VCard::fromQuery(Contact::active())->download();

// With custom constraints
return VCard::fromQuery(
    Contact::where('country', 'SA')->orderBy('first_name')
)->download();

Important: When using fromQuery(), apply all conditions directly to the query before passing it in. Do not chain where() on the VCard facade alongside fromQuery().


From a DB::table Query

return VCard::fromQuery(
    DB::table('contacts')->where('active', 1)
)->download();

Custom Filename

return VCard::download('company_employees');
// Output: company_employees_150.vcf

Full Control β€” All Options Combined

return VCard::fromQuery(Contact::active())
    ->map([
        'first_name'   => 'fname',
        'last_name'    => 'lname',
        'phone_mobile' => 'mobile',
        'phone_work'   => 'work_phone',
        'email'        => 'email',
    ])
    ->withLastName()
    ->withEmail()
    ->filename('contacts_export')
    ->chunkSize(1000)
    ->download();

πŸ“‹ Configuration Reference

| Option | Description | Default | |--------|-------------|---------| | table | Database table name | contacts | | filename | Output filename without .vcf extension | contacts | | append_count | Append the total record count to the filename | true | | append_date | Append today's date to the filename | false | | skip_empty_phone | Skip records that have no phone number | true | | normalize_phone | Strip symbols and formatting from phone numbers | true | | charset_utf8 | Enable UTF-8 charset for Arabic name support | true | | chunk_size | Number of records to process per chunk | 500 |


πŸ“– API Reference

| Method | Description | |--------|-------------| | from(string $table) | Set the database table to query | | fromQuery($query) | Pass in a ready-made Eloquent or DB::table query builder | | map(array $columns) | Override the column mapping at runtime | | where(array $conditions) | Add WHERE conditions (only works with from()) | | withLastName() | Enable the last name field | | withEmail() | Enable the email field | | filename(string $name) | Set a custom output filename | | chunkSize(int $size) | Override the chunk size for this export | | download(?string $filename) | Execute the export and stream the .vcf file |


πŸ—οΈ Package Structure

src/
β”œβ”€β”€ Support/
β”‚   β”œβ”€β”€ ExportConfig.php       ← Data object holding all resolved settings
β”‚   └── ColumnMap.php          ← Column mapping between config keys and DB columns
β”œβ”€β”€ VCardBuilder.php           ← Builds vCard 3.0 formatted strings
β”œβ”€β”€ VCardDownloader.php        ← Reads from DB in chunks and streams the file
β”œβ”€β”€ VCardExporter.php          ← The fluent API builder
β”œβ”€β”€ Facades/
β”‚   └── VCard.php              ← Laravel Facade
└── Providers/
    └── VCardServiceProvider.php

config/
└── vcard-exporter.php

πŸ“‹ Requirements

| Requirement | Version | |-------------|---------| | PHP | ^8.3 | | Laravel | ^10 \| ^11 \| ^12 |


πŸ“„ License

Open source, released under the MIT License.


Made with ❀️ by Developer Abod

Comments