Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Talk Laravel Package

nahid/talk

Talk adds a full user-to-user conversation system to Laravel: create conversations, threaded messages, pagination, read/seen status, soft/permanent deletes, participant-only access, URL embedding, and optional realtime messaging for chat-like experiences.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer (composer require nahid/talk) and publishing its assets with php artisan vendor:publish --provider="Nahid\Talk\TalkServiceProvider". Run migrations to set up the required tables (conversation, message, message_user). Configure your user model in config/talk.php, then register the Talk middleware (talk) in app/Http/Kernel.php and apply it to routes where messaging is needed. To begin, inject the authenticated user ID using either Talk::setAuthUserId(auth()->id()) (e.g., in controller constructor) or chain operations with Talk::user(auth()->id())->.... A quick first use is sending a message:

$conversationId = Talk::isConversationExists($receiverId) ?: 
    Talk::sendMessageByUserId($receiverId, 'Hello!')->conversation_id;

Explore the example app at https://github.com/nahid/talk-example for a working reference.

Implementation Patterns

  • Controller Setup: Use middleware or explicit setAuthUserId()/user() calls to scope all Talk operations to the current user.
  • Real-time Setup: Enable broadcasting in config/talk.php ('broadcast' => ['enable' => true, ...]) and configure Pusher or laravel-websockets. Listen for Talk\MessageSent events on the frontend using Echo.
  • Message Flow:
    • Create/send: Use sendMessageByUserId() if the conversation doesn’t exist yet (creates on-the-fly), or sendMessage() if you already have a conversation_id.
    • Inbox listing: Talk::user($id)->threads() or getInbox() retrieves paginated conversation threads with latest messages.
    • View messages: getConversationsByUserId($receiverId) or messages($conversationId) for full thread history.
  • Frontend Integration:
    • Render UI from $inbox->withUser (user info) and $inbox->thread (latest message) in inbox lists.
    • Use getConversationsById($id) to load a full conversation with sender info and timestamps.
  • Seen & Deletion: Call makeSeen($messageId) when user opens a thread; use deleteMessage($messageId) to soft-delete per user (restored via messagesAll* methods).

Gotchas and Tips

  • Legacy Migration Warning: Avoid direct migration from v1.1.7 to newer versions; test against the official example repo first.
  • Auth Scoping: Always ensure setAuthUserId() or user() is called before querying— Talk defaults to null auth, yielding empty results silently.
  • Middleware Conflict: Don’t apply the talk middleware globally unless all routes require auth user scoping; prefer per-controller application.
  • Broadcasting Pitfalls: Broadcast fails silently if Pusher credentials are missing or the app isn’t configured for WebSocket events. Double-check config/broadcasting.php and JS setup.
  • Deprecated Methods: getReceiverInfo() is deprecated—use $message->withUser or $message->sender relationships instead.
  • Soft Deletes: getInbox() excludes soft-deleted messages; use threadsAll()/getInboxAll() if you need recovery UX (e.g., trash folder).
  • Pagination: All listing methods accept $offset and $take parameters (e.g., threads('desc', 0, 20))—handle pagination in your controller, not the view.
  • Inline URLs: Enable oembed in config/talk.php and validate target URLs to embed rich previews—disabled by default.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport