Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use LaravelFCM\Message\OptionsBuilder;
- use LaravelFCM\Message\PayloadDataBuilder;
- use LaravelFCM\Message\PayloadNotificationBuilder;
- use FCM;
- class PushNotificationSend extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'push_notification:send';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $optionBuilder = new OptionsBuilder();
- $optionBuilder->setTimeToLive(60*20);
- $notificationBuilder = new PayloadNotificationBuilder();
- $notificationBuilder->setTitle('Hello')->setBody('world')
- ->setSound('default');
- $dataBuilder = new PayloadDataBuilder();
- $dataBuilder->addData([
- 'body' => 'hello',
- 'title' => 'hello world',
- 'notification' => [
- 'name' => 'mahmud',
- 'age' => 25
- ]
- ]);
- $option = $optionBuilder->build();
- $notification = $notificationBuilder->build();
- $data = $dataBuilder->build();
- $token = "afT67fauFSG0:APA91bERkTizELghpP0G1lguz6gvwS0DgMdMfhq0UZrfWAnxIIzmjnFGtuHPbNfhf4M0Tm3oHZx7naVg0ph3XljaeZZ6qq0kBAEVv56DunGbLFQCtYZHG2Fdo8NG2hvOXasHz-c1war7a";
- $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);
- dd(
- $downstreamResponse->numberSuccess(),
- $downstreamResponse->numberFailure()
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement