Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First parameter must either be an object or the name of an existing class {"exception":"[object] (ErrorException(code: 0) #376

Open
Gabotron-ES opened this issue Sep 8, 2023 · 2 comments

Comments

@Gabotron-ES
Copy link

Gabotron-ES commented Sep 8, 2023

In my laravel app I'm getting the following error message from Pusher, i'm a bit lost on what the error exactly means bit it seems to be triggered on this Pusher method:

Pusher\Pusher->trigger(Array, 'App\\ Events\\ NewC...', Array, Array)

So apparently the problem is I'm passing an array instead of an object or class, the thing is I'm using laravel broadcast method to trigger events on my app, this works on local but for production is giving me this error for some reason...

broadcast(new NewChatEvent())

My event:

class NewChatEvent implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $data;
    

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    

    public function broadcastOn()
    {
        //return new Channel('chat.receiver.1');
        return new Channel('chat.receiver.'.$this->data['receiver']['id']);
    }

}
```

And my channels file:

```
<?php

use Illuminate\Support\Facades\Broadcast;
use App\Models\User;
use App\Models\Chat;

/*
|--------------------------------------------------------------------------
| Broadcast Channels
|--------------------------------------------------------------------------
|
| Here you may register all of the event broadcasting channels that your
| application supports. The given channel authorization callbacks are
| used to check if an authenticated user can listen to the channel.
|
*/


Broadcast::channel('chat.receiver.{id}', function ($user, $id) {
    //return (int) $user->id === (int) $id;
    return true;
});
```
The full error is here:
```
[2023-09-03 23:39:53] production.ERROR: First parameter must either be an object or the name of an existing class {"exception":"[object] (ErrorException(code: 0): First parameter must either be an objec
t or the name of an existing class at /var/www/laraapp.com/vendor/pusher/pusher-php-server/src/Pusher.php:538)
[stacktrace]
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'First parameter...', '/var/www/woolov...', 538, Array)
#1 /var/www/laraapp.com/vendor/pusher/pusher-php-server/src/Pusher.php(538): property_exists(NULL, 'channels')
#2 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php(125): Pusher\Pusher->trigger(Array, 'App\\
Events\\NewC...', Array, Array)
#3 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(77): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast(Array, 'App\\Events\\NewC...', Array)
#4 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\BroadcastManager))
#5 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#6 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#7 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#8 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#9 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call(Array)
#10 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#11 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
#12 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#13 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php(119): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Broadcasting\BroadcastEvent))
#14 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(320): Illuminate\Broadcasting\BroadcastManager->queue(Object(App\Events\NewChatEvent))
#15 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(243): Illuminate\Events\Dispatcher->broadcastEvent(Object(App\Events\NewChatEvent))
#16 /var/www/laraapp.com/vendor/laravel/framework/src/Illuminate/Broadcasting/PendingBroadcast.php(72): Illuminate\Events\Dispatcher->dispatch('App\\Events\\NewC...')
#17 
```

How can I fix this?
Copy link

stale bot commented Dec 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you.

@stale stale bot added the wontfix label Dec 15, 2023
@benw-pusher
Copy link

I believe you got in touch with Support for this, do you still need assistance?

@stale stale bot removed the wontfix label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants