0

I am trying to use Pusher's vanilla PHP library within my controller.

This is what I'm trying to do:

include( app_path().'/includes/Pusher.php' );

$pusher = new Pusher('KEY', 'KEY', '1234');
$pusher->trigger('bid_channel', 'NewBid', $auction);

I know there are Pusher packages but every one of them is broken in some way or another. The vinkla packages Facades don't work.

I have used the above code successfully in routes.php to test it but when I put it in my controller I get this error:

FatalErrorException in APIController.php line 40: Class 'App\Http\Controllers\Pusher' not found

Any help would be appreciated!

KriiV
  • 1,882
  • 4
  • 25
  • 43
  • possible duplicate of [Importing class without namespace to namespaced class](http://stackoverflow.com/questions/8574794/importing-class-without-namespace-to-namespaced-class) – scrowler Aug 10 '15 at 05:07
  • It's possible to use dependency injection or rename the facade all together to get the *vinkla/pusher* package working. – Jeemusu Aug 10 '15 at 05:11
  • @Jeemusu I prefer using Facades. I just don't know how to rename it properly: http://stackoverflow.com/questions/31912408/renaming-a-facade-conflicts – KriiV Aug 10 '15 at 05:51

1 Answers1

2

You need to reference the class Pusher in it's namespace. It doesn't seem to take advantage of specific namespaces, so it's namespace will be the base namespace.

Try:

$pusher = new \Pusher('KEY', 'KEY', '123');

This is because at the top of your controller file there will be:

namespace App\Http\Controllers;

This puts the file into the App\Http\Controllers namespace, so anything in the base namespace will have to have the leading slash which indicates the class is in the base namespace.

KriiV
  • 1,882
  • 4
  • 25
  • 43
Scopey
  • 6,269
  • 1
  • 22
  • 34