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/ */
// 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();