Giter VIP home page Giter VIP logo

pusher-beams's Introduction

Pusher Beams - push notifications for Laravel

Latest Version on Packagist Software License Build Status StyleCI Quality Score

This package makes it easy to send Pusher push notifications with Laravel (should work with other non-laravel PHP projects). It's based off this package by Mohamed Said.

Contents

Installation

You can install the package via composer:

composer require neo/pusher-beams

...

Setting up your Pusher account

...

Usage

Update your .env file with the following keys:

PUSHER_BEAMS_SECRET_KEY="PUSHER_BEAMS_SECRET_KEY"
PUSHER_BEAMS_INSTANCE_ID="PUSHER_BEAMS_INSTANCE_ID"

๐Ÿ’ก You need to replace the PUSHER_BEAMS_SECRET_KEY and PUSHER_BEAMS_INSTANCE_ID keys with the keys gotten from your Pusher dashboard.

Open the broadcasting.php file in the config directory and add the following keys to the pusher connection array:

'connections' => [
    'pusher' => [
        // [...]

        'beams' => [
            'secret_key' => env('PUSHER_BEAMS_SECRET_KEY'),
            'instance_id' => env('PUSHER_BEAMS_INSTANCE_ID'),
        ],

        // [...]
    ],
],

Next, create a new notification class where we will add our push notification. In your terminal run the command below to create the class:

$ php artisan make:notification UserCommented

This will create a new UserCommented class in the app/Notifications directory. Open the file and you can do something similar to this sample class:

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Neo\PusherBeams\PusherBeams;
use Neo\PusherBeams\PusherMessage;
use App\User;
use App\PhotoComment;
use App\Photo;

class UserCommented extends Notification
{
    use Queueable;

    public $user;

    public $comment;

    public $photo;

    public function __construct(User $user, Photo $photo, PhotoComment $comment)
    {
        $this->user = $user;
        
        $this->comment = $comment;
        
        $this->photo = $photo;
    }

    public function via($notifiable)
    {
        return [PusherBeams::class];
    }

    public function toPushNotification($notifiable)
    {
        return PusherMessage::create()
            ->iOS()
            ->sound('success')
            ->title('New Comment')
            ->body("{$this->user->name} commented on your photo: {$this->comment->comment}")
            ->setOption('apns.aps.mutable-content', 1)
            ->setOption('apns.data.attachment-url', $this->photo->image);
    }

    public function pushNotificationInterest()
    {
        $id = $this->photo->id;

        $audience = strtolower($this->user->settings->notification_comments);

        return "photo_{$id}-comment_{$audience}";
    }
}

In the class above we are extending a Notification class and we have implemented the toPushNotification method, which will be used to send the push notification when required. In the via method, we specify what channels we want to send the notification through and in the pushNotificationInterest we specify the interest we want to publish the push notification to.

Sending to multiple platforms

...

Routing a message

...

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

pusher-beams's People

Contributors

ichtrojan avatar neoighodaro avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pusher-beams's Issues

Peer dependency conflict with Laravel 8.x

Unable to run composer install with neo/pusher-beams and

  • Laravel version 8.x and higher
  • PHP 8.0.10
  • Composer version 2.1.8

Error:

  Problem 1
    - neo/pusher-beams v1.0.0 requires illuminate/events 5.3.* || 5.4.* || 5.5.* || 5.6.* -> found illuminate/events[v5.3.0, ..., 5.6.x-dev] but these were not loaded, likely because it conflicts with another require.
    - neo/pusher-beams[v1.0.1, ..., v1.0.3] require illuminate/events 5.5.* || 5.6.* -> found illuminate/events[v5.5.0, ..., 5.6.x-dev] but these were not loaded, likely because it conflicts with another require.
    - neo/pusher-beams v1.0.4 requires illuminate/events 5.5.* || 5.6.* || 5.7.* -> found illuminate/events[v5.5.0, ..., 5.7.x-dev] but these were not loaded, likely because it conflicts with another require.
    - neo/pusher-beams v1.0.5 requires illuminate/events 5.5.* || 5.6.* || 5.7.* || ^6.0 || ^7.0 -> found illuminate/events[v5.5.0, ..., 5.7.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but these were not loaded, likely because it conflicts with another require.
    - Root composer.json requires neo/pusher-beams ^1.0 -> satisfiable by neo/pusher-beams[v1.0.0, ..., v1.0.5].

I really think it is necessary to add an update to make the package compatible with latest version of Laravel and resolve conflicts with the dependencies.

Usage

Thanks for the effort to make this but it looks like no readme or documentation. Could you please update those

Call to undefined function Neo\PusherBeams\array_get()

app->when(PusherBeams::class) ->needs(PushNotifications::class) ->give(function () { $pusherConfig = config('broadcasting.connections.pusher'); return new PushNotifications([ 'secretKey' => array_get($pusherConfig, 'beams.secret_key'), 'instanceId' => array_get($pusherConfig, 'beams.instance_id'), ]); }); } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.