0

In my laravel.log i can see the event is broadcasting on the channel i.e.

[2018-08-30 13:41:27] local.INFO: Broadcasting [App\Events\NewRating] on channels [rating] with payload:
{
    "music": {
        "id": 42,
        "name": "1535368873_admin.mp3",
        "path": "public\/music\/1535368873_admin.mp3",
        "rating": 53,
        "user_id": 4,
        "created_at": "2018-08-27 11:21:13",
        "updated_at": "2018-08-27 11:21:13",
        "is_last_played": 1,
        "is_now_playing": 0,
        "location_id": 1
    },
    "socket": null
}  

As of i know i have done everything according to requirement.my redis server is running.laravel-echo-server is running and it is joining my channel i.e.

[18:41:24] - VX9bkHqs-QHRv3MvAAAC joined channel: rating

This is where i am subscribing to the channel and listening to the event

window.app = new Vue({
        el: '#app',

        beforeMount: function () {
        alert("asdas");
        this.joinPublicChatChannel();
        },

        methods: {
        joinPublicChatChannel: function () {
            Echo.channel('rating').listen('App\\Events\\NewRating', (event) => {
                console.log("Event fired!"); //This doesnt work
            });
            }
        }
});

and this is my event class

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

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

    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('rating');
    }
}

and this is my env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel_restaurant
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=redis
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=

Dont know the reason behind :/

UPDATE

Just cleared all the caches, Now im getting this in laravel-echo-server console

Channel: rating
Event: App\Events\NewRating
Channel: rating
Event: App\Events\NewRating
Channel: rating
Event: App\Events\NewRating

2 Answers 2

1

you can use this in your event file :

public function broadcastAs()
{
    return 'NewRating';
}
Sign up to request clarification or add additional context in comments.

Comments

0

Never Mind, I got this running :). just cleared the caches and in

Echo.channel('rating').listen('App\\Events\\NewRating', (event) => {
            console.log("Event fired!"); //This doesnt work
        });

I used NewRating instead of App\\Events\\NewRating

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.