PHP code example of makidizajnerica / laravel-multiemail

1. Go to this page and download the library: Download makidizajnerica/laravel-multiemail 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/ */

    

makidizajnerica / laravel-multiemail example snippets


'providers' => [

    // Laravel's default provider
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Models\User::class,
    ],

    'emails' => [
        'driver' => 'eloquent.email',
        'models' => [
            'user' => App\Models\User::class,
            'email' => MakiDizajnerica\MultiEmail\Models\Email::class,
        ],
    ],

],

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'emails', // <- edit this line
    ],
],

'passwords' => [
    'users' => [
        'provider' => 'emails', // <- edit this line
        'table' => 'password_resets',
        'expire' => 60,
        'throttle' => 60,
    ],
],

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Queue\QueueServiceProvider::class,
    Illuminate\Redis\RedisServiceProvider::class,

    Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, // <- remove this line
    MakiDizajnerica\MultiEmail\Providers\PasswordResetServiceProvider::class, // <- add this line

    Illuminate\Session\SessionServiceProvider::class,
    Illuminate\Translation\TranslationServiceProvider::class,
],

'user_model' => \Custom\Namespace\User::class,

namespace App\Models;

use MakiDizajnerica\MultiEmail\HasMultipleEmails;
use Illuminate\Foundation\Auth\User as Authenticatable;
use MakiDizajnerica\MultiEmail\Contracts\HasMultipleEmails as HasMultipleEmailsContract;

class User extends Authenticatable implements HasMultipleEmailsContract
{
    use HasMultipleEmails;
    
    //
}

use MakiDizajnerica\MultiEmail\Models\Email;

public function emails() : HasMany
{
    return $this->hasMany(Email::class);
}

/**
 * Add new email address.
 *
 * @param  array $email
 * @param  bool $sendVerification
 * @return \MakiDizajnerica\MultiEmail\Email
 */
public function addNewEmail(array $email, $sendVerification = true);

/**
 * Find email address.
 *
 * @param  mixed $email
 * @param  string $field
 * @return \MakiDizajnerica\MultiEmail\Email|null
 */
public function findMyEmail($email, $field = 'email');

/**
 * Determine if user is the owner of the provided email address.
 *
 * @param  string $email
 * @return bool
 */
public function isMyEmail($email);

/**
 * Remove all user's email addresses.
 *
 * @return void
 */
public function removeAllEmails();

/**
 * Check if the provided email address is verified.
 *
 * @param  string $email
 * @return bool
 */
public function isVerifiedEmail($email);

/**
 * Determine if provided email address is primary.
 *
 * @param  string $email
 * @return bool
 */
public function isPrimaryEmail($email);

/**
 * Change primary email address.
 *
 * @param  string $email
 * @return void
 */
public function setEmailAsPrimary($email);

/**
 * Determine if user has recovery email address.
 *
 * @return bool
 */
public function hasRecoveryEmail();

/**
 * Determine if provided email address is recovery.
 *
 * @param  string $email
 * @return bool
 */
public function isRecoveryEmail($email);

/**
 * Change recovery email address.
 *
 * @param  string $email
 * @return void
 */
public function setEmailAsRecovery($email);

// Get all user's verified emails
$user->verified_emails

// Get primary email
$user->email

// Get recovery email if it exists
$user->recovery_email

use App\Models\User;

$user = User::first();

$email = $user->addNewEmail([
    'email' => '[email protected]'
]);

use App\Models\User;
use Illuminate\Support\Facades\Hash;

$user = User::create([
    'name' => 'Nick',
    'password' => Hash::make('password'),
]);

$email = $user->addNewEmail([
    'email' => '[email protected]',
    'type' => 'primary',
]);

use App\Models\User;
use Illuminate\Support\Facades\Hash;

$user = User::create([
    'name' => 'Nick',
    'password' => Hash::make('password'),
]);

$email = $user->addNewEmail([
    'email' => '[email protected]',
    'type' => 'primary',
    'verified_at' => now(),
], false);

use App\Models\User;

$user = User::first();

if ($user->isMyEmail('[email protected]')) {

    // Set as primary
    $user->setEmailAsPrimary('[email protected]');
    
    // Set as recovery
    $user->setEmailAsRecovery('[email protected]');

}

'passwords' => [
    'allow_resets' => true,
    'reset_with_primary_email' => true,
],
bash
php artisan vendor:publish --tag=multiemail-config
bash
php artisan vendor:publish --tag=multiemail-migrations
bash
php artisan migrate