feat: Implement real-time chat with Reverb
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<script setup>
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { route } from 'ziggy-js';
|
||||
import { onMounted } from 'vue';
|
||||
import { useEcho } from '@laravel/echo-vue';
|
||||
|
||||
const props = defineProps({
|
||||
chat: Object,
|
||||
@@ -10,6 +12,15 @@ const form = useForm({
|
||||
content: '',
|
||||
});
|
||||
|
||||
const echo = useEcho();
|
||||
|
||||
onMounted(() => {
|
||||
echo.private(`chats.${props.chat.id}`)
|
||||
.listen('MessageSent', (e) => {
|
||||
props.chat.messages.push(e.message);
|
||||
});
|
||||
});
|
||||
|
||||
function submit() {
|
||||
form.post(route('chats.messages.store', props.chat.id), {
|
||||
onSuccess: () => form.reset(),
|
||||
|
||||
Reference in New Issue
Block a user