PHP code example of laravel-notification-channels / authy

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

    

laravel-notification-channels / authy example snippets


    /**
     * Route notifications for the authy channel.
     *
     * @return int
     */
    public function routeNotificationForAuthy()
    {
        return $this->authy_id;
    }
    

    // app/Notifications/PhoneVerificationNotification.php

    namespace App\Notifications;

    use Illuminate\Notifications\Notification;
    use NotificationChannels\Authy\AuthyChannel;
    use NotificationChannels\Authy\AuthyMessage;

    class PhoneVerificationNotification extends Notification
    {
        /**
         * The notification method (sms/call).
         *
         * @var string
         */
        public $method;

        /**
         * Determine whether to force the notification over cellphone network.
         *
         * @var bool
         */
        public $force;

        /**
         * The notification message action.
         *
         * @var string
         */
        public $action;

        /**
         * The notification message action message.
         *
         * @var string
         */
        public $actionMessage;

        /**
         * Create a notification instance.
         *
         * @param string $method
         * @param bool   $force
         * @param string $action
         * @param string $actionMessage
         *
         * @return void
         */
        public function __construct($method = 'sms', $force = false, $action = null, $actionMessage = null)
        {
            $this->method = $method;
            $this->force = $force;
            $this->action = $action;
            $this->actionMessage = $actionMessage;
        }

        /**
         * Get the notification's channels.
         *
         * @param mixed $notifiable
         *
         * @return array|string
         */
        public function via($notifiable)
        {
            return [AuthyChannel::class];
        }

        /**
         * Build the Authy representation of the notification.
         *
         * @return \NotificationChannels\Authy\AuthyMessage
         */
        public function toAuthy()
        {
            $message = AuthyMessage::create()->method($this->method);

            if ($this->force) {
                $message->force();
            }

            if ($this->action) {
                $message->action($action);
            }

            if ($this->actionMessage) {
                $message->actionMessage($actionMessage);
            }

            return $message;
        }
    }
    

    $this->notify(new \App\Notifications\PhoneVerificationNotification('sms', true));