laravel socket when pass string give error

Viewed 13

hello guys i hope to be fine all ,I have problem when use laravel socket and test it working or not by event add pass string in route give me this error

event (NotificationRecieved) file

class NotificationRecieved implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $notification;


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

public function broadcastOn()
{
    return new Channel('Notification');
}


public function broadcastWith()
{
    $notifications = [
        'notification' => $this->notification
    ];
    return $notifications;
}
}

vue component file

<template>
<h1>iam vue,systme say: {{notification}}</h1>
</template>


<script>
export default{
    name:"app",
    data(){
        return{
            notification:""
        }
    },
    mounted(){
        window.Echo.channel('Notification').listen('NotificationRecieved',event =>{
            this.notification = event.notification
        })
    }
}
</script>

route file

Route::get('/', function () {
return view('welcome');
});

Route::get('/notify/{notification}', function ($notification) {
return event(new NotificationRecieved($notification));
});

enter image description here

0 Answers
Related