Skip to content

Instantly share code, notes, and snippets.

@mottihoresh
Last active November 17, 2019 20:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mottihoresh/394e12ea802b41b5ef65 to your computer and use it in GitHub Desktop.
Save mottihoresh/394e12ea802b41b5ef65 to your computer and use it in GitHub Desktop.
Basic Pusher Integration with Laravel 5

Place the PusherWrapper inside your '''App/Services''' directory Place the pusher.php inside your config folder.

<?php
return [
'appId' => 'YOUR-APP-ID-HERE',
'appKey' => 'YOUR-APP-KEY-HERE',
'appSecret' => 'YOUR-APP-SECRET-HERE',
];
<?php
/**
* Created by PhpStorm.
* User: mhoresh
* Date: 3/7/15
* Time: 4:15 PM
*/
namespace App\Services;
use Illuminate\Support\Facades\Config;
class PusherWrapper {
protected $pusher;
function __construct()
{
$app_id = Config::get('pusher.appId');
$app_key = Config::get('pusher.appKey');
$app_secret = Config::get('pusher.appSecret');
$this->pusher = new \Pusher( $app_key, $app_secret, $app_id );
}
public function __call($name, $args) {
returncall_user_func_array(array($this->pusher, $name), $args);
}
}
@mottihoresh
Copy link
Author

No Idea how to write introduction... but just inject that service anywhere, and you can use it.

for example

    public function test( \App\Services\PusherWrapper $pusher){
        $pusher->trigger('channel', 'event', ['data'=>'some data']]);
    }

@TeddyBear06
Copy link

Great thanks. You just missed a space in the _call method :

public function __call($name, $args) {
    return call_user_func_array(array($this->pusher, $name), $args);
}

@Porkts
Copy link

Porkts commented Dec 30, 2017

Tanks man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment