Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] Allow to override Nexmo client via NexmoMessage #30

Merged
merged 1 commit into from
Dec 10, 2019
Merged

[2.x] Allow to override Nexmo client via NexmoMessage #30

merged 1 commit into from
Dec 10, 2019

Conversation

tzurbaev
Copy link
Contributor

This PR adds ability to override underlying Nexmo\Client instance with custom client. This helps in situations when you have some customer/DB-stored credentials and you need to send SMS using given credentials (not with the system-wide that are stored in services.php).

Example code:

<?php

declare(strict_types=1);

namespace App\Notifications;

use Illuminate\Notifications\Messages\NexmoMessage;
use Illuminate\Notifications\Notification;
use App\Models\Company;
use Nexmo\Client;

class ExampleNotification extends Notification
{
    private Company $company;

    public function __construct(Company $company)
    {
        $this->company = $company;
    }

    public function toNexmo($notifiable): NexmoMessage
    {
        return (new NexmoMessage('Something happened!'))
            ->from($this->company->nexmo_from)
            ->via($this->getCompanyClient());
    }

    private function getCompanyClient(): Client
    {
        return new Client(
            new Client\Credentials\Basic(
                $this->company->nexmo_key,
                $this->company->nexmo_secret
            )
        );
    }
}

@driesvints driesvints changed the title Allow to override Nexmo client via NexmoMessage [2.x] Allow to override Nexmo client via NexmoMessage Dec 10, 2019
@taylorotwell taylorotwell merged commit 27b28f4 into laravel:2.0 Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants