There are a few Laravel bridges/wrappers for the Pusher PHP library that allow you to integrate with Pusher. The most popular bridge we know of is vinkla/pusher by Vincent Klaiber.
Let's start by installing the package:
› composer require vinkla/pusher
Next let's add the vinkla/pusher package service provider to the providers array in config/app.php:
Vinkla\Pusher\PusherServiceProvider::class,
And then publish so the Pusher configuration file is copied to the config directory:
› php artisan vendor:publish
Then set up the the vinkla/pusher vendor configuration in config/pusher.php to use the environment variables. Update the auth_key, secret and app_id values of the main connection as follows:
'connections' => [
'main' => [
'auth_key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [],
'host' => null,
'port' => null,
'timeout' => null,
],
config/pusher.php Gotcha!
Make sure you've updated config/pusher.php and not vendor/vinkla/pusher/config/pusher.php.
Once that's set up we can get access to a Pusher instance directly using the Service Container or indirectly via Dependency Injection.
To quickly test this, open app/Http/routes.php and add:
use Illuminate\Support\Facades\App;
get('/bridge', function() {
$pusher = App::make('pusher');
$pusher->trigger( 'test-channel',
'test-event',
array('text' => 'Preparing the Pusher Laracon.eu workshop!'));
return view('welcome');
});
We'll cover the details of this in a later exercise.
Next we want to test that this is working. To do this:
php artisan serve (if it's not already running)You'll now see the event appear in the Pusher Debug Console. It's working!
Next, let's see how the same thing can be achieved using the Laravel Event Broadcaster.