PHP code example of 3neti / laravel-model-channel

1. Go to this page and download the library: Download 3neti/laravel-model-channel 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/ */

    

3neti / laravel-model-channel example snippets


use Illuminate\Database\Eloquent\Model;
use LBHurtado\ModelChannel\Contracts\HasMobileChannel;
use LBHurtado\ModelChannel\Contracts\HasWebhookChannel;
use LBHurtado\ModelChannel\Traits\HasChannels;

class User extends Model implements HasMobileChannel, HasWebhookChannel
{
    use HasChannels;
}

$user->setMobileChannel('09171234567');

$user->getMobileChannel(); // 639171234567
$user->hasMobileChannel(); // true

$user->setMobileChannel('09171234567');
$user->setMobileChannel('0917 123 4567');
$user->setMobileChannel('639171234567');
$user->setMobileChannel('+639171234567');
$user->setMobileChannel('+63 (917) 123-4567');

639171234567

$user->setWebhookChannel('https://example.com/webhook');

$user->getWebhookChannel(); // https://example.com/webhook
$user->hasWebhookChannel(); // true

$user->setChannel('webhook', 'https://example.com/webhook');

$user->getChannel('webhook');
$user->hasChannel('webhook');

use LBHurtado\ModelChannel\Enums\Channel;

$user->setChannel(Channel::WEBHOOK, 'https://example.com/webhook');

$user->setChannel(Channel::WEBHOOK, null);
$user->setChannel(Channel::WEBHOOK, '');

$user->mobile = '09171234567';

$user->mobile;              // 639171234567
$user->getMobileChannel();  // 639171234567

$user->setTelegramChannel('123456789');
$user->getTelegramChannel();
$user->hasTelegramChannel();

$user->setWhatsappChannel('09171234567');
$user->getWhatsappChannel();
$user->hasWhatsappChannel();

$user->setViberChannel('09171234567');
$user->getViberChannel();
$user->hasViberChannel();

User::findByMobile('09171234567');
User::findByWebhook('https://example.com/webhook');
User::findByChannel('telegram', '123456789');

$table->index(['name', 'value']);
$table->index(['model_type', 'model_id', 'name']);

'cache' => [
    'enabled' => true,
    'ttl' => 600,
    'channels' => ['mobile', 'webhook'],
]

use LBHurtado\ModelChannel\Contracts\HasMobileChannel;

function sendOtp(HasMobileChannel $user)
{
    $mobile = $user->getMobileChannel();
}