93 lines
2.2 KiB
Markdown
93 lines
2.2 KiB
Markdown
|
# 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:
|
||
|
|
||
|
```bash
|
||
|
composer require bluesquare/laravel-push
|
||
|
```
|
||
|
|
||
|
If you want to customize the config system:
|
||
|
|
||
|
```bash
|
||
|
php artisan vendor:publish
|
||
|
```
|
||
|
|
||
|
Finally, copy your API key from Bluesquare Push (senders section), and add it in your `.env`:
|
||
|
|
||
|
```bash
|
||
|
PUSH_API_KEY=your_api_key
|
||
|
```
|
||
|
|
||
|
You may also want to use your own API:
|
||
|
|
||
|
```bash
|
||
|
PUSH_API_URL=https://push.bluesquare.io/api/send
|
||
|
```
|
||
|
|
||
|
## Usage
|
||
|
|
||
|
First, create a new notification or use an existing one:
|
||
|
|
||
|
```bash
|
||
|
php artisan make:notification MyAwesomeNotification
|
||
|
```
|
||
|
|
||
|
Add BluescaleMailChannel in the `via()` method:
|
||
|
|
||
|
```php
|
||
|
return [PushChannel::class];
|
||
|
```
|
||
|
|
||
|
Then, create a 'toTemplate()' method, in which you specify your template fields :
|
||
|
|
||
|
```php
|
||
|
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:
|
||
|
|
||
|
```php
|
||
|
User::first()->notify(new MyAwesomeNotification);
|
||
|
```
|
||
|
|
||
|
|