Maxime 6de775c8b7 | ||
---|---|---|
config | ||
src | ||
.gitignore | ||
README.md | ||
composer.json |
README.md
laravel-push
The Bluesquare Push package allows you to send Push templates using Laravel notification system.
Installation
First prepare your composer.json:
composer config repositories.push vcs https://git.bluesquare.io/bluesquare/laravel-push.git -n
Then install the package:
composer require bluesquare/laravel-push
If you want to customize the config system:
php artisan vendor:publish
Finally, copy your API key from Bluesquare Push (senders section), and add it in your .env
:
PUSH_API_KEY=your_api_key
You may also want to use your own API:
PUSH_API_URL=https://push.bluesquare.io/api/send
Usage
First, create a new notification or use an existing one:
php artisan make:notification MyAwesomeNotification
Add BluescaleMailChannel in the via()
method:
return [PushChannel::class];
Then, create a 'toTemplate()' method, in which you specify your template fields :
public function toTemplate($notifiable)
{
return (new PushTemplate("my-template-slug"))
->sender("john.doe@gmail.com", "John OPTIONAL") // OPTIONAL
->replyTo("jean.grey@gmail.com", "Jean OPTIONAL") // OPTIONAL
->recipients([
[
"email" => "elvis@gmail.com",
"name": "Elvis", // OPTIONAL
"parameters": ["key" => "value"] // OPTIONAL
"unsubscribe_url": "https://my-unsubscribe-url.com" // OPTIONAL
],
// ...
])
->addRecipient("edward@gmail.com") // OPTIONAL
->addRecipient(
email: "edward@gmail.com",
name: "Edward", // OPTIONAL
parameters: ["key" => "value"], // OPTIONAL
unsubscribe_url: "https://my-unsubscribe-url.com" // OPTIONAL
)
->parameters(["key" => "value", "key" => "value"]) // OPTIONAL
->addParameter("key", "value") // OPTIONAL
->bulkMode() // OPTIONAL
->testMode() // OPTIONAL
->unsubscribeUrl("https://group-unsubscribe-url.com") // OPTIONAL
;
}
The $notifiable is automatically added as recipient.
In your controller, you can now send your template:
User::first()->notify(new MyAwesomeNotification);