0

Using Pusher with Laravel 5.8 to send messages in real-time generates this error on NewMessage Event file. Steps I took to try and debug:

  1. tried removing the line "use Dispatchable, InteractsWithSockets, SerializesModels;" inside the Class;

  2. tried without using the Classes at the top of the file

none of those worked. On Laravel 5.8 Documentation they don't mention using this line inside our Event Classes, maybe it's outdated?!

File looks like this:

`

namespace StyxEminus\Events;
use StyxEminus\Message;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class NewMessage implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $message;

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

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{
    return new PrivateChannel('messages.' . $this->message->to);
}

public function broadcastWith() {
    return ["message" => $this->message];
}
}`

Local Server: Apache on Xampp; Operating System: W10 64bit Browser: Brave(chromium) & Chrome

r.gjoni
  • 45
  • 7
  • composer dump can help – Dry7 Jun 18 '19 at 21:11
  • @Dry7 the output looks like this: Generated optimized autoload files containing 3638 classes Discovered Package: barryvdh/laravel-cors Discovered Package: beyondcode/laravel-dump-server Discovered Package: fideloper/proxy Discovered Package: laravel/tinker Discovered Package: nesbot/carbon Discovered Package: nunomaduro/collision – r.gjoni Jun 18 '19 at 21:13
  • Is the error still left? – Dry7 Jun 18 '19 at 21:26
  • Yes the error still persists – r.gjoni Jun 18 '19 at 21:29
  • composer update --no-scripts https://stackoverflow.com/questions/29764368/fatal-error-class-illuminate-foundation-application-not-found – Dry7 Jun 18 '19 at 21:32
  • Doing that removed barryvdh/laravel-cors & asm89/stack-cors, the public directory gives another error: "Class 'Barryvdh\Cors\ServiceProvider' not found" and the initial error is still there – r.gjoni Jun 18 '19 at 21:37

1 Answers1

0

you need import Illuminate\Foundation\Bus\Dispatchable

Dry7
  • 861
  • 1
  • 8
  • 17