PHP code example of sormagec / pusher-beam-laravel

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

    

sormagec / pusher-beam-laravel example snippets


$publishResponse = PusherBeams::publishToInterests(
  "body" => "Hello, world!",
  ["donuts"],
  [
    "apns" => [
      "aps" => [
	    "alert" => "Hello!",
      ],
    ],
    "fcm" => [
      "notification" => [
        "title" => "Hello!",
        "body" => "Hello, world!",
      ],
    ],
  ]
);

echo("Published with Publish ID: " . $publishResponse->publishId . "\n");

$publishResponse = PuhserBeams::publishToUsers(
  ["user-0001"],
  [
    "apns" => [
      "aps" => [
        "alert" => "Hello!",
      ],
    ],
    "fcm" => [
      "notification" => [
        "title" => "Hello!",
        "body" => "Hello, world!",
      ],
    ],
  ]
);

echo("Published with Publish ID: " . $publishResponse->publishId . "\n");

Pusher\Beams\Laravel\PusherBeamsServiceProvider::class

'PusherBeams' => Pusher\Beams\Laravel\Facades\PusherBeams::class

// You can alias this in config/app.php.
use Pusher\Beams\Laravel\Facades\PusherBeams;

PusherBeams::publish(
	["hello", "donuts"],
	[
		"fcm" => [
			"notification" => [
				"title" => "Hi!",
				"body" => "This is my first Push Notification!"
				]
		],
		"apns" => ["aps" => [
				"alert" => [
					"title" => "Hi!",
					"body" => "This is my first Push Notification!"
				]
		]]
	]
);
// We're done here - how easy was that, it just works!

use Pusher\Beams\Laravel\Facades\PusherBeams;

// Writing this…
PusherBeams::connection('main')->publish([...]);

// …is identical to writing this
PusherBeams::publish([...]);

// and is also identical to writing this.
PusherBeams::connection()->publish([...]);

// This is because the main connection is configured to be the default.
PusherBeams::getDefaultConnection(); // This will return main.

// We can change the default connection.
PusherBeams::setDefaultConnection('alternative'); // The default is now alternative.

use Pusher\Beams\Laravel\PusherBeamsManager;

class Foo
{
    protected $pusherBeams;

    public function __construct(PusherBeamsManager $pusherBeams)
    {
        $this->pusherBeams = $pusherBeams;
    }

    public function bar()
    {
        $this->pusherBeams->publish('my-channel', 'my-event', ['message' => $message]);
    }
}

App::make('Foo')->bar();
bash
$ php artisan vendor:publish --provider="Pusher\Beams\Laravel\PusherBeamsServiceProvider"