abdellatif-laghjaj / laravel-chat-app

A real time private chat application using Laravel 9, Vue Js 3, Pusher and Laravel Echo
45 stars 13 forks source link

Hy can you please help me.. #2

Open afaqahmad1234 opened 1 year ago

afaqahmad1234 commented 1 year ago

can you please help me. how can i start conversation with any user from blade file

@extends('layouts.app')

@section('content')
    <tbody >
        @foreach ($contacts as $contact)
            <tr>
                <td>
                    <h4>{{ $contact->name }}</h4>
                </td>
                <td>
                    <button>Chat</button>
                </td>

            </tr>
        @endforeach
    </tbody>
@endsection
ERaufi commented 1 year ago

base on the video you added in facebook send you can achieve that by sending the contact id with the URL parameter

@extends('layouts.app')

@section('content')
    <tbody >
        @foreach ($contacts as $contact)
            <tr>
                <td>
                    <h4>{{ $contact->name }}</h4>
                </td>
                <td>
        <a href="your_chat_page_link/{{$contact->id}}">
         <button>Chat</button>
         </a>
                </td>

            </tr>
        @endforeach
    </tbody>
@endsection

and in your route Route::get('your_chat_page_link/{id}',[YOUR_CONTROLLER::class,'YOUR_METHOD_NAME'])

then in your YOUR_CONTROLLER where you redirect to your blade file just send the id or name with the help you compact

afaqahmad1234 commented 1 year ago

base on the video you added in facebook send you can achieve that by sending the contact id with the URL parameter

@extends('layouts.app')

@section('content')
    <tbody >
        @foreach ($contacts as $contact)
            <tr>
                <td>
                    <h4>{{ $contact->name }}</h4>
                </td>
                <td>
        <a href="your_chat_page_link/{{$contact->id}}">
         <button>Chat</button>
         </a>
                </td>

            </tr>
        @endforeach
    </tbody>
@endsection

and in your route Route::get('your_chat_page_link/{id}',[YOUR_CONTROLLER::class,'YOUR_METHOD_NAME'])

then in your YOUR_CONTROLLER where you redirect to your blade file just send the id or name with the help you compact

Thank you for your effort, but it did not work its created in vue.js can you please check it https://github.com/abdellatif-laghjaj/laravel-chat-app/tree/main/resources/js/components

abdellatif-laghjaj commented 1 year ago

Hello, I used Vue js to pass data through components, but in case you want to use blade instead of it, you can do a specific route (just like our friend told you to do), by getting the contact details via contact id, and when you click on it you show all the messages between you and that contact!

afaqahmad1234 commented 1 year ago

Hello, I used Vue js to pass data through components, but in case you want to use blade instead of it, you can do a specific route (just like our friend told you to do), by getting the contact details via contact id, and when you click on it you show all the messages between you and that contact!

yes i did this but did not work this. because in vue we have used @selected="startConvo", when open that chat page it should be selected already. but i don't know how to do this. I'm workin in vue.js for first time

<ContactList :contacts="contacts" :messages="messages" @selected="startConvo"/> <Conversation :contact="selectedContact" :messages="messages" @new="saveNewMessage" />