PHP code example of shadowbane / laravel-wablas

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

    

shadowbane / laravel-wablas example snippets


namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Shadowbane\LaravelWablas\Exceptions\FailedToSendNotification;
use Shadowbane\LaravelWablas\LaravelWablasChannel;
use Shadowbane\LaravelWablas\LaravelWablasMessage;

class WhatsappNotification extends Notification
{
    protected string $phoneNumber;
    protected string $message;

    /**
     * Create a new notification instance.
     *
     * @param string $phoneNumber
     * @param string $message;
     *
     * @return void
     */
    public function __construct(string $phoneNumber, string $message)
    {
        $this->phoneNumber = $phoneNumber;
        $this->message = $message;
    }

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

    /**
     * @param $notifiable
     *
     * @throws FailedToSendNotification
     *
     * @return LaravelWablasMessage
     */
    public function toWhatsapp($notifiable)
    {
        return LaravelWablasMessage::create()
            ->to($this->phoneNumber)
            ->content($this->message);
    }
}


    use Shadowbane\LaravelWablas\LaravelWablasMessage;
    
    ...

    public function toWhatsapp($notifiable)
    {
        return LaravelWablasMessage::create()
            ->token('this-is-another-token-in-my-application')
            ->to($this->phoneNumber)
            ->content($this->message);
    }

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Shadowbane\LaravelWablas\LaravelWablasChannel;
use Shadowbane\LaravelWablas\LaravelWablasMessage;

class WhatsappNotification extends Notification
{
    protected string $phoneNumber;
    protected string $message;

    /**
     * Create a new notification instance.
     *
     * @param string $message;
     *
     * @return void
     */
    public function __construct(string $message)
    {
        $this->message = $message;
    }

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

    /**
     * @param $notifiable
     *
     * @return LaravelWablasMessage
     */
    public function toWhatsapp($notifiable)
    {
        return LaravelWablasMessage::create()
            ->content($this->message);
    }
}

use App\Notifications\WhatsappNotification;

$user->notify(new WhatsappNotification($message));



    use Shadowbane\LaravelWablas\LaravelWablasMessage;

    ...

    public function toWhatsapp($notifiable)
    {
        return LaravelWablasMessage::create()
            ->token('this-is-another-token-in-my-application')
            ->to([$destination1, $destination2])
            ->content($this->message);
    }

use Illuminate\Support\Facades\Notification;
use App\Models\User;
use App\Notifications\WhatsappNotification;

Notification::send(User::whereSomeCondition(1)->get(), new WhatsappNotification(123) );

php artisan vendor:publish --provider="Shadowbane\LaravelWablas\LaravelWablasServiceProvider"