PHP code example of mischasigtermans / laravel-sift

1. Go to this page and download the library: Download mischasigtermans/laravel-sift library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mischasigtermans / laravel-sift example snippets


use MischaSigtermans\Sift\Facades\Sift;

// Extract business domains (filters public providers by default)
Sift::domain('[email protected]');     // 'company.com'
Sift::domain('[email protected]');       // null (filtered)

// Check if email is business or personal
Sift::isBusiness('[email protected]'); // true
Sift::isBusiness('[email protected]');   // false

// Validate in form requests
$request->validate([
    'email' => ['

Sift::domain('[email protected]');   // 'example.com'
Sift::domain('[email protected]'); // 'sub.domain.org'

// These return null (filtered as public providers)
Sift::domain('[email protected]');
Sift::domain('[email protected]');
Sift::domain('[email protected]');

// Business domains pass through
Sift::domain('[email protected]');    // 'stripe.com'
Sift::domain('[email protected]');    // 'company.io'

// Include public domains when needed
Sift::domain('[email protected]', true); // 'gmail.com'

Sift::isCommon('gmail.com');           // true
Sift::isCommon('[email protected]'); // true
Sift::isCommon('company.com');         // false

// Or check if it's a business email
Sift::isBusiness('[email protected]');  // true
Sift::isBusiness('[email protected]');    // false

use MischaSigtermans\Sift\Rules\BusinessEmail;

// Using the rule class directly
$request->validate([
    'email' => ['

$emails = [
    '[email protected]',
    '[email protected]',
    '[email protected]',
    '[email protected]',
];

// Extract unique business domains (filters personal emails)
Sift::domains($emails);
// ['acme.com', 'stripe.com']

// Extract all unique domains without filtering
Sift::extractAll($emails);
// ['acme.com', 'stripe.com', 'gmail.com']

// Include personal domains
Sift::domains($emails, 

$emails = [
    '[email protected]',
    '[email protected]',
    '[email protected]',
    '[email protected]',
    '[email protected]',
];

$stats = Sift::stats($emails);
// [
//     'total' => 5,
//     'business' => 3,
//     'personal' => 2,
//     'business_rate' => 60.0,
//     'top_domains' => [
//         'acme.com' => 2,
//         'stripe.com' => 1,
//     ],
// ]

// Limit top domains returned
$stats = Sift::stats($emails, topDomainsLimit: 5);

Sift::domain('[email protected]');   // null
Sift::domain('[email protected]'); // 'company.com'
Sift::isCommon('YAHOO.COM');      // true

// config/sift.php
return [
    // Add extra domains to filter (on top of package defaults)
    'additional_domains' => [
        'competitor.com',
        'internal-tool.io',
    ],

    // Whitelist specific defaults (allow them as business emails)
    'exclude_default_domains' => [
        'protonmail.com', // Allow privacy-focused provider
        'fastmail.com',
    ],
];

use MischaSigtermans\Sift\DefaultDomains;

// Get the full list of 100+ default domains
DefaultDomains::LIST;

// Or get the merged list (defaults + additional - excluded)
Sift::getCommonDomains();

public function store(Request $request)
{
    $request->validate([
        'email' => ['' => Sift::domain($request->email),
    ]);
}

public function emailStats()
{
    $emails = User::pluck('email');

    return Sift::stats($emails);
    // Shows business vs personal breakdown with top company domains
}

$users = User::all()->groupBy(function ($user) {
    return Sift::domain($user->email, true) ?? 'personal';
});

// [
//     'acme.com' => [...users from acme.com...],
//     'stripe.com' => [...users from stripe.com...],
//     'personal' => [...users with gmail, yahoo, etc...],
// ]

public function calculateDiscount(User $user): int
{
    if (Sift::isBusiness($user->email)) {
        return 20; // 20% enterprise discount
    }

    return 0;
}
bash
php artisan vendor:publish --tag=sift-config