This Laravel application manages chat messages between users using Laravel Echo, Pusher, and WebSockets for real-time updates.
The MessageSentEvent broadcasts new chat messages using private channels based on sender and receiver IDs.
sendMessage: Handles sending messages between users.getChatHistory: Retrieves chat history for a specific user.markAsRead: Marks messages as read for a user.contacts: Retrieves contacts for a user.getAllChats: Retrieves all chat messages.
- Transforms
ChatMessagemodel data into JSON responses, including sender and receiver information.
- Validates and handles requests to send messages, ensuring sender and receiver IDs are valid and different.
- Defines methods for managing chat messages.
- Implements
ChatMessageInterfacemethods using Eloquent models for database operations.
- Orchestrates message sending, broadcasting, and retrieval operations using the repository.
The frontend uses Laravel Echo and Pusher to listen for new messages and update the UI in real-time.
- Clone the repository.
- Install dependencies:
composer installandnpm install. - Configure
.envfor database and Pusher settings. - Run migrations:
php artisan migrate. - Compile frontend assets:
npm run dev.
- Register/login users.
- Start sending messages between users.
- View chat history, mark messages as read, and manage contacts.