pusher-http-laravel: Error Using the Facade

The error below has been reported by @alexandredes and @mottihoresh. This error occurs when using the Facade. As I’ve learned, using dependency injection it works.

call_user_func_array() expects parameter 1 to be a valid callback

I’ve tried this in my local setup, using Homestead, with both the Facade and dependency injection without any problems. The events gets registered in the console at http://pusher.com. Example code below.

<?php namespace App\Http\Controllers;

use Vinkla\Pusher\Facades\Pusher;

class PushController extends Controller {

    public function index()
    {
        dd(Pusher::trigger('my-channel', 'my-event', ['message' => 'A']));
    }

}

unnamed

If someone else experience this, please report it here. If you have a solution, please share it!

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 3
  • Comments: 47 (19 by maintainers)

Commits related to this issue

Most upvoted comments

For the time being, I’ve just renamed my facade to LaravelPusher to great success. In my controller I call use LaravelPusher; then I can use

public function pusher()
{
    $messages = '{"name":"Joe","message":"Hello world!"}';

    LaravelPusher::trigger('test_channel', 'my_event', ['message' => $messages]);
}

in my function. My alias then has to become 'LaravelPusher' => 'Vinkla\Pusher\Facades\Pusher',.

As mentioned above, it’s because the class and facade clash for the namespace.

@rulatir https://github.com/vinkla/pusher#installation follow the instructions this way

Installation

Require this package, with Composer, in the root directory of your project.

composer require vinkla/pusher

Add the service provider to config/app.php in the providers array.

Vinkla\Pusher\PusherServiceProvider::class

If you want you can use the facade. Add the reference in config/app.php to your aliases array.

'Pusher' => Vinkla\Pusher\Facades\Pusher::class //IGNORE THIS

If you prefer to use dependency injection over facades like me, then you can inject the manager:

use Vinkla\Pusher\PusherManager;

class Foo
{
    protected $pusher;

    public function __construct(PusherManager $pusher)
    {
        $this->pusher = $pusher;
    }

    public function bar()
    {
        $this->pusher->trigger('my-channel', 'my-event', ['message' => $message]);
    }
}

@luismfonseca let me know if there is anything I can help with. Please let me know before you push the new version. Then I can help you test it out.

Yes, but you need to release it as a new major version. It is a breaking change. Shouldn’t be a problem though since integers are cheap.